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 May 9, 2024
1 parent 7440e83 commit 73ae097
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 103 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 @@ -2275,7 +2275,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 @@ -2333,6 +2333,7 @@ type Item {
pinboardId: String!
mentions: [MentionHandle!]
groupMentions: [MentionHandle!]
chatBotMentions: [String!]
claimedByEmail: String
claimable: Boolean!
relatedItemId: String
Expand Down Expand Up @@ -2370,9 +2371,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 @@ -2410,6 +2418,7 @@ input CreateItemInput {
pinboardId: String!
mentions: [String!]
groupMentions: [String!]
chatBotMentions: [String!]
claimable: Boolean
relatedItemId: String
}
Expand Down Expand Up @@ -2492,7 +2501,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 @@ -2513,7 +2522,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 @@ -2534,7 +2543,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 @@ -2555,7 +2564,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 @@ -2576,7 +2585,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 @@ -2597,7 +2606,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 @@ -2618,7 +2627,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 @@ -2639,7 +2648,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 @@ -2660,7 +2669,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 @@ -2681,7 +2690,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 @@ -2702,7 +2711,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 @@ -2723,7 +2732,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 @@ -2744,7 +2753,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 @@ -2765,7 +2774,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 @@ -2786,7 +2795,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 @@ -2807,7 +2816,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 @@ -2932,7 +2941,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 @@ -2953,7 +2962,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 @@ -3078,7 +3087,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 @@ -3099,7 +3108,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 @@ -3120,7 +3129,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
44 changes: 26 additions & 18 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 @@ -35,7 +41,9 @@ export const AvatarRoundel = ({
height: ${size}px;
border-radius: 50%;
box-shadow: 0 0 1px ${neutral[93]};
background-color: ${composer.primary[300]};
background-color: ${isChatBot(maybeUserOrGroupOrChatBot)
? "none"
: composer.primary[300]};
color: ${neutral[100]};
display: flex;
flex-shrink: 0;
Expand All @@ -47,17 +55,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 73ae097

Please sign in to comment.