Skip to content

Commit

Permalink
WIP add ChatBot support
Browse files Browse the repository at this point in the history
  • Loading branch information
twrichards committed Nov 10, 2023
1 parent 61775e6 commit c3c8125
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 102 deletions.
55 changes: 32 additions & 23 deletions cdk/lib/__snapshots__/stack.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ type Query {
listItems(pinboardId: String!): [Item]
listLastItemSeenByUsers(pinboardId: String!): [LastItemSeenByUser]
getMyUser: MyUser
searchMentionableUsers(prefix: String!): UsersAndGroups
searchMentionableUsers(prefix: String!): UsersGroupsAndChatBots
getUsers(emails: [String!]!): [User]
getGroupPinboardIds: [PinboardIdWithClaimCounts!]!
getItemCounts(pinboardIds: [String!]!): [PinboardIdWithItemCounts!]!
Expand Down Expand Up @@ -2308,6 +2308,7 @@ type Item {
pinboardId: String!
mentions: [MentionHandle!]
groupMentions: [MentionHandle!]
chatBotMentions: [String!]
claimedByEmail: String
claimable: Boolean!
relatedItemId: String
Expand Down Expand Up @@ -2345,9 +2346,16 @@ type Group {
memberEmails: [String!]!
}
type UsersAndGroups {
type ChatBot {
shorthand: String!
description: String!
avatarUrl: String
}
type UsersGroupsAndChatBots {
users: [User!]!
groups: [Group!]!
chatBots: [ChatBot!]!
}
type WorkflowStub {
Expand Down Expand Up @@ -2385,6 +2393,7 @@ input CreateItemInput {
pinboardId: String!
mentions: [String!]
groupMentions: [String!]
chatBotMentions: [String!]
claimable: Boolean
relatedItemId: String
}
Expand Down Expand Up @@ -2467,7 +2476,7 @@ type PinboardIdWithItemCounts {
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "addManuallyOpenedPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2488,7 +2497,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "claimItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2509,7 +2518,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "createItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2530,7 +2539,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "deleteItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2551,7 +2560,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "editItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2572,7 +2581,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "removeManuallyOpenedPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2593,7 +2602,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "seenItem",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2614,7 +2623,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "setWebPushSubscriptionForUser",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2635,7 +2644,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "visitTourStep",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Mutation",
},
Expand All @@ -2656,7 +2665,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getGroupPinboardIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2677,7 +2686,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getItemCounts",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2698,7 +2707,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getMyUser",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2719,7 +2728,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "getUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2740,7 +2749,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "listItems",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2761,7 +2770,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "listLastItemSeenByUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2782,7 +2791,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "database_bridge_lambda_ds",
"FieldName": "searchMentionableUsers",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down Expand Up @@ -2907,7 +2916,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "grid_bridge_lambda_ds",
"FieldName": "asGridPayload",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -2928,7 +2937,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "grid_bridge_lambda_ds",
"FieldName": "getGridSearchSummary",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down Expand Up @@ -3053,7 +3062,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "getPinboardByComposerId",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -3074,7 +3083,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "getPinboardsByIds",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand All @@ -3095,7 +3104,7 @@ $util.toJson($ctx.result)",
"DataSourceName": "workflow_bridge_lambda_ds",
"FieldName": "listPinboards",
"Kind": "UNIT",
"ResponseMappingTemplate": "## schema checksum : aa02bae16942e48366fa36a1cd643d16
"ResponseMappingTemplate": "## schema checksum : a54e7dc179390650f513c62f63e1cfe7
$util.toJson($ctx.result)",
"TypeName": "Query",
},
Expand Down
5 changes: 5 additions & 0 deletions client/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export const gqlSearchMentionableUsers = (prefix: string) => gql`
name
memberEmails
}
chatBots {
shorthand
description
avatarUrl
}
}
}
`;
Expand Down
40 changes: 23 additions & 17 deletions client/src/avatarRoundel.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { css } from "@emotion/react";
import { neutral } from "@guardian/source-foundations";
import React from "react";
import { Group, User } from "../../shared/graphql/graphql";
import { ChatBot, Group, User } from "../../shared/graphql/graphql";
import { composer } from "../colours";
import { agateSans } from "../fontNormaliser";
import { isUser } from "../../shared/graphql/extraTypes";
import {
hasAvatarUrl,
isChatBot,
isGroup,
isUser,
} from "../../shared/graphql/extraTypes";

interface AvatarRoundelProps {
maybeUserOrGroup: User | Group | undefined;
maybeUserOrGroupOrChatBot: User | Group | ChatBot | undefined;
size: number;
fallback: string;
}

export const AvatarRoundel = ({
maybeUserOrGroup,
maybeUserOrGroupOrChatBot,
size,
fallback,
}: AvatarRoundelProps) =>
maybeUserOrGroup && isUser(maybeUserOrGroup) && maybeUserOrGroup.avatarUrl ? (
hasAvatarUrl(maybeUserOrGroupOrChatBot) &&
maybeUserOrGroupOrChatBot.avatarUrl ? (
<img
key={fallback}
css={css`
border-radius: 50%;
width: ${size}px;
height: ${size}px;
`}
src={maybeUserOrGroup.avatarUrl}
src={maybeUserOrGroupOrChatBot.avatarUrl}
draggable={false}
/>
) : (
Expand All @@ -47,17 +53,17 @@ export const AvatarRoundel = ({
line-height: ${size}px;
`}
>
{maybeUserOrGroup ? (
isUser(maybeUserOrGroup) ? (
<React.Fragment>
{maybeUserOrGroup.firstName.charAt(0).toUpperCase()}
{maybeUserOrGroup.lastName?.charAt(0).toUpperCase()}
</React.Fragment>
) : (
maybeUserOrGroup.memberEmails?.length
)
) : (
fallback.charAt(0).toUpperCase()
{isUser(maybeUserOrGroupOrChatBot) && (
<React.Fragment>
{maybeUserOrGroupOrChatBot.firstName.charAt(0).toUpperCase()}
{maybeUserOrGroupOrChatBot.lastName?.charAt(0).toUpperCase()}
</React.Fragment>
)}
{isGroup(maybeUserOrGroupOrChatBot) &&
maybeUserOrGroupOrChatBot.memberEmails?.length}
{isChatBot(maybeUserOrGroupOrChatBot) && (
<span>🤖</span> /* TODO replace with actual bot SVG */
)}
{!maybeUserOrGroupOrChatBot && fallback.charAt(0).toUpperCase()}
</span>
);
2 changes: 1 addition & 1 deletion client/src/itemDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const ItemDisplay = ({
{isDifferentUserFromPreviousItem && (
<React.Fragment>
<AvatarRoundel
maybeUserOrGroup={user}
maybeUserOrGroupOrChatBot={user}
size={28}
fallback={item.userEmail}
/>
Expand Down
Loading

0 comments on commit c3c8125

Please sign in to comment.