Skip to content

Commit

Permalink
Merge pull request #384 from cofacts/use-ar-time
Browse files Browse the repository at this point in the history
feat(webhook): display article reply's time instead of replies' time
  • Loading branch information
MrOrz authored Jan 10, 2024
2 parents 3f0b28c + 007c2e4 commit 1d089c5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
export const oneReply = {
import { GetReplyRelatedDataQuery } from 'typegen/graphql';

export const oneReply: { data: GetReplyRelatedDataQuery } = {
data: {
GetReply: {
type: 'NOT_ARTICLE',
text: '這是商業活動廣告01 這是商業活動廣告02 這是商業活動廣告03 這是商業活動廣告04 這是商業活動廣告05 這是商業活動廣告06 這是商業活動廣告07 這是商業活動廣告08 這是商業活動廣告09 這是商業活動廣告10 這是商業活動廣告11 這是商業活動廣告12 這是商業活動廣告13 這是商業活動廣告14 這是商業活動廣告15 這是商業活動廣告16 這是商業活動廣告17 這是商業活動廣告18 這是商業活動廣告19 這是商業活動廣告20',
reference: '',
createdAt: '2018-01-09T05:52:12.658Z',
createdAt: '2017-01-09T05:52:12.658Z',
},
GetArticle: {
text: '(0)(1)(/)(0)(9)(line)免費貼圖\n「[全螢幕貼圖]生活市集x生活小黑熊」\n https://line.me/S/sticker/',
replyCount: 1,
createdAt: '2018-01-02T05:52:12.658Z',
articleReplies: [
{
replyId: 'AWDZeeV0yCdS-nWhuml8',
createdAt: '2018-01-09T05:52:12.658Z',
},
],
},
},
};

export const oneReply2 = {
export const oneReply2: { data: GetReplyRelatedDataQuery } = {
data: {
GetReply: {
type: 'RUMOR',
Expand All @@ -26,22 +34,32 @@ export const oneReply2 = {
replyCount: 1,
text: 'Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply ',
createdAt: '2018-01-02T05:52:12.658Z',
articleReplies: [],
},
},
};

export const multipleReplies = {
export const multipleReplies: { data: GetReplyRelatedDataQuery } = {
data: {
GetReply: {
type: 'NOT_ARTICLE',
text: '這是商業活動廣告01 這是商業活動廣告02 這是商業活動廣告03 這是商業活動廣告04 這是商業活動廣告05 這是商業活動廣告06 這是商業活動廣告07 這是商業活動廣告08 這是商業活動廣告09 這是商業活動廣告10 這是商業活動廣告11 這是商業活動廣告12 這是商業活動廣告13 這是商業活動廣告14 這是商業活動廣告15 這是商業活動廣告16 這是商業活動廣告17 這是商業活動廣告18 這是商業活動廣告19 這是商業活動廣告20',
reference: '',
createdAt: '2018-01-09T05:52:12.658Z',
createdAt: '2017-01-09T05:52:12.658Z',
},
GetArticle: {
text: '(0)(1)(/)(0)(9)(line)免費貼圖\n「[全螢幕貼圖]生活市集x生活小黑熊」\n https://line.me/S/sticker/',
replyCount: 4,
createdAt: '2018-01-02T05:52:12.658Z',
articleReplies: [
{ replyId: 'another-one', createdAt: '2015-01-09T05:52:12.658Z' },
{ replyId: 'another-two', createdAt: '2015-01-10T05:52:12.658Z' },
{ replyId: 'another-three', createdAt: '2015-01-11T05:52:12.658Z' },
{
replyId: 'AWDZeeV0yCdS-nWhuml8',
createdAt: '2018-01-09T05:52:12.658Z',
},
],
},
},
};
18 changes: 17 additions & 1 deletion src/webhook/handlers/choosingReply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ const choosingReply: ChatbotPostbackHandler = async ({
text
replyCount
createdAt
articleReplies {
replyId
createdAt
}
}
}
`<GetReplyRelatedDataQuery, GetReplyRelatedDataQueryVariables>({
Expand All @@ -190,8 +194,20 @@ const choosingReply: ChatbotPostbackHandler = async ({
userId
);

const articleReplyCreatedAt = GetArticle.articleReplies.find(
({ replyId }) => replyId === selectedReplyId
)?.createdAt;

const replies: Message[] = [
...createReplyMessages(GetReply, GetArticle, selectedArticleId),
...createReplyMessages(
{
...GetReply,
// Use articleReply's createdAt instead of reply's createdAt
createdAt: articleReplyCreatedAt ?? GetReply.createdAt,
},
GetArticle,
selectedArticleId
),
{
type: 'flex',
altText: t`Is the reply helpful?`,
Expand Down
13 changes: 9 additions & 4 deletions typegen/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
*/
const documents = {
"\n mutation SubmitTextArticleUnderConsent($text: String!) {\n CreateArticle(text: $text, reference: { type: LINE }) {\n id\n }\n }\n ": types.SubmitTextArticleUnderConsentDocument,
"\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n ": types.SubmitMediaArticleUnderConsentDocument,
"\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n ": types.SubmitMediaArticleUnderConsentDocument,
"\n query GetArticleInChoosingArticle($id: String!) {\n GetArticle(id: $id) {\n text\n replyCount\n articleType\n articleReplies(status: NORMAL) {\n reply {\n id\n type\n text\n }\n positiveFeedbackCount\n negativeFeedbackCount\n }\n createdAt\n }\n }\n ": types.GetArticleInChoosingArticleDocument,
"\n mutation SubmitReplyRequestWithoutReason($id: String!) {\n CreateOrUpdateReplyRequest(articleId: $id) {\n replyRequestCount\n }\n }\n ": types.SubmitReplyRequestWithoutReasonDocument,
"\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n }\n }\n ": types.GetReplyRelatedDataDocument,
"\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n articleReplies {\n replyId\n createdAt\n }\n }\n }\n ": types.GetReplyRelatedDataDocument,
"fragment CreateReferenceWordsReply on Reply {\n reference\n type\n createdAt\n}\n\nfragment CreateReplyMessagesReply on Reply {\n text\n ...CreateReferenceWordsReply\n}\n\nfragment CreateReplyMessagesArticle on Article {\n replyCount\n createdAt\n}\n\nfragment CreateHighlightContentsHighlight on Highlights {\n text\n hyperlinks {\n title\n summary\n }\n}": types.CreateReferenceWordsReplyFragmentDoc,
"\n mutation CreateAIReply($articleId: String!) {\n CreateAIReply(articleId: $articleId) {\n text\n createdAt\n }\n }\n ": types.CreateAiReplyDocument,
"\n query ListArticlesInInitState($text: String!) {\n ListArticles(\n filter: { moreLikeThis: { like: $text } }\n orderBy: [{ _score: DESC }]\n first: 4\n ) {\n edges {\n node {\n id\n text\n articleType\n attachmentUrl(variant: THUMBNAIL)\n }\n highlight {\n text\n hyperlinks {\n title\n summary\n }\n }\n }\n }\n }\n ": types.ListArticlesInInitStateDocument,
"\n query ListArticlesInProcessMedia($mediaUrl: String!) {\n ListArticles(\n filter: {\n mediaUrl: $mediaUrl\n articleTypes: [TEXT, IMAGE, AUDIO, VIDEO]\n transcript: { shouldCreate: true }\n }\n orderBy: [{ _score: DESC }]\n first: 9\n ) {\n edges {\n score\n mediaSimilarity\n node {\n id\n articleType\n attachmentUrl(variant: THUMBNAIL)\n }\n highlight {\n text\n hyperlinks {\n title\n summary\n }\n }\n }\n }\n }\n ": types.ListArticlesInProcessMediaDocument,
"\n mutation SetCooccurrences($articleIds: [String!]!) {\n CreateOrUpdateCooccurrence(articleIds: $articleIds) {\n id\n }\n }\n ": types.SetCooccurrencesDocument,
};

/**
Expand All @@ -45,7 +46,7 @@ export function graphql(source: "\n mutation SubmitTextArticleUnderCons
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n "): (typeof documents)["\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n "];
export function graphql(source: "\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n "): (typeof documents)["\n mutation SubmitMediaArticleUnderConsent(\n $mediaUrl: String!\n $articleType: ArticleTypeEnum!\n ) {\n CreateMediaArticle(\n mediaUrl: $mediaUrl\n articleType: $articleType\n reference: { type: LINE }\n ) {\n id\n }\n }\n "];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand All @@ -57,7 +58,7 @@ export function graphql(source: "\n mutation SubmitReplyRequestWithoutReaso
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n }\n }\n "): (typeof documents)["\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n }\n }\n "];
export function graphql(source: "\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n articleReplies {\n replyId\n createdAt\n }\n }\n }\n "): (typeof documents)["\n query GetReplyRelatedData($id: String!, $articleId: String!) {\n GetReply(id: $id) {\n type\n text\n reference\n createdAt\n }\n GetArticle(id: $articleId) {\n text\n replyCount\n createdAt\n articleReplies {\n replyId\n createdAt\n }\n }\n }\n "];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand All @@ -74,6 +75,10 @@ export function graphql(source: "\n query ListArticlesInInitState($text: Stri
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query ListArticlesInProcessMedia($mediaUrl: String!) {\n ListArticles(\n filter: {\n mediaUrl: $mediaUrl\n articleTypes: [TEXT, IMAGE, AUDIO, VIDEO]\n transcript: { shouldCreate: true }\n }\n orderBy: [{ _score: DESC }]\n first: 9\n ) {\n edges {\n score\n mediaSimilarity\n node {\n id\n articleType\n attachmentUrl(variant: THUMBNAIL)\n }\n highlight {\n text\n hyperlinks {\n title\n summary\n }\n }\n }\n }\n }\n "): (typeof documents)["\n query ListArticlesInProcessMedia($mediaUrl: String!) {\n ListArticles(\n filter: {\n mediaUrl: $mediaUrl\n articleTypes: [TEXT, IMAGE, AUDIO, VIDEO]\n transcript: { shouldCreate: true }\n }\n orderBy: [{ _score: DESC }]\n first: 9\n ) {\n edges {\n score\n mediaSimilarity\n node {\n id\n articleType\n attachmentUrl(variant: THUMBNAIL)\n }\n highlight {\n text\n hyperlinks {\n title\n summary\n }\n }\n }\n }\n }\n "];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation SetCooccurrences($articleIds: [String!]!) {\n CreateOrUpdateCooccurrence(articleIds: $articleIds) {\n id\n }\n }\n "): (typeof documents)["\n mutation SetCooccurrences($articleIds: [String!]!) {\n CreateOrUpdateCooccurrence(articleIds: $articleIds) {\n id\n }\n }\n "];

export function graphql(source: string) {
return (documents as any)[source] ?? {};
Expand Down
Loading

0 comments on commit 1d089c5

Please sign in to comment.