Skip to content

Commit

Permalink
refactor(webhook): combine carousel generator for both media and text…
Browse files Browse the repository at this point in the history
… search
  • Loading branch information
MrOrz committed Jan 9, 2024
1 parent 7e38887 commit 2c3e500
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 320 deletions.
9 changes: 9 additions & 0 deletions src/webhook/handlers/__fixtures__/initState.ts

Large diffs are not rendered by default.

98 changes: 33 additions & 65 deletions src/webhook/handlers/__tests__/__snapshots__/initState.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Please choose the version that looks the most similar👇",
Object {
"color": "#ff7b7b",
"size": "sm",
"text": "(Words found in transcript)",
"text": "(Text in transcript)",
"type": "text",
"weight": "bold",
},
Expand All @@ -80,15 +80,13 @@ Please choose the version that looks the most similar👇",
],
"flex": 0,
"gravity": "top",
"maxLines": 6,
"maxLines": 12,
"type": "text",
"weight": "regular",
"wrap": true,
},
],
"layout": "vertical",
"margin": "none",
"spacing": "none",
"type": "box",
},
"direction": "ltr",
Expand All @@ -97,7 +95,7 @@ Please choose the version that looks the most similar👇",
Object {
"action": Object {
"data": "{\\"input\\":\\"AVvY-yizyCdS-nWhuYWx\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
"displayText": "I choose “計程車上有裝悠遊卡感應器,老人悠悠卡可以享受...”",
"displayText": "I choose ",
"label": "Choose this one",
"type": "postback",
},
Expand All @@ -111,26 +109,22 @@ Please choose the version that looks the most similar👇",
},
"header": Object {
"contents": Array [
Object {
"flex": 0,
"text": "😀",
"type": "text",
},
Object {
"color": "#AAAAAA",
"gravity": "center",
"size": "sm",
"text": "Looks 52% similar",
"text": "Looks 52% similar",
"type": "text",
"weight": "bold",
"wrap": true,
},
],
"layout": "horizontal",
"paddingBottom": "none",
"spacing": "md",
"paddingBottom": "md",
"spacing": "sm",
"type": "box",
},
"hero": undefined,
"type": "bubble",
},
Object {
Expand Down Expand Up @@ -273,15 +267,13 @@ Please choose the version that looks the most similar👇",
],
"flex": 0,
"gravity": "top",
"maxLines": 6,
"maxLines": 12,
"type": "text",
"weight": "regular",
"wrap": true,
},
],
"layout": "vertical",
"margin": "none",
"spacing": "none",
"type": "box",
},
"direction": "ltr",
Expand All @@ -290,7 +282,7 @@ Please choose the version that looks the most similar👇",
Object {
"action": Object {
"data": "{\\"input\\":\\"AVvY-yizyCdS-nWhuYWx\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
"displayText": "I choose “YouTube · 寻找健康人生”",
"displayText": "I choose ",
"label": "Choose this one",
"type": "postback",
},
Expand All @@ -304,26 +296,22 @@ Please choose the version that looks the most similar👇",
},
"header": Object {
"contents": Array [
Object {
"flex": 0,
"text": "😄",
"type": "text",
},
Object {
"color": "#AAAAAA",
"gravity": "center",
"size": "sm",
"text": "Looks 100% similar",
"text": "Looks 100% similar",
"type": "text",
"weight": "bold",
"wrap": true,
},
],
"layout": "horizontal",
"paddingBottom": "none",
"spacing": "md",
"paddingBottom": "md",
"spacing": "sm",
"type": "box",
},
"hero": undefined,
"type": "bubble",
},
Object {
Expand Down Expand Up @@ -352,15 +340,13 @@ Please choose the version that looks the most similar👇",
],
"flex": 0,
"gravity": "top",
"maxLines": 6,
"maxLines": 12,
"type": "text",
"weight": "regular",
"wrap": true,
},
],
"layout": "vertical",
"margin": "none",
"spacing": "none",
"type": "box",
},
"direction": "ltr",
Expand All @@ -369,9 +355,7 @@ Please choose the version that looks the most similar👇",
Object {
"action": Object {
"data": "{\\"input\\":\\"AVvY-yizyCdS-nWhuYWy\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
"displayText": "I choose “YouTube
·
寻找健康人生”",
"displayText": "I choose ②",
"label": "Choose this one",
"type": "postback",
},
Expand All @@ -385,26 +369,22 @@ Please choose the version that looks the most similar👇",
},
"header": Object {
"contents": Array [
Object {
"flex": 0,
"text": "😄",
"type": "text",
},
Object {
"color": "#AAAAAA",
"gravity": "center",
"size": "sm",
"text": "Looks 100% similar",
"text": "Looks 100% similar",
"type": "text",
"weight": "bold",
"wrap": true,
},
],
"layout": "horizontal",
"paddingBottom": "none",
"spacing": "md",
"paddingBottom": "md",
"spacing": "sm",
"type": "box",
},
"hero": undefined,
"type": "bubble",
},
],
Expand Down Expand Up @@ -766,7 +746,7 @@ Please choose the version that looks the most similar👇",
Object {
"color": "#ff7b7b",
"size": "sm",
"text": "(Words found in the hyperlink)",
"text": "(Text in the hyperlink)",
"type": "text",
"weight": "bold",
},
Expand Down Expand Up @@ -820,15 +800,13 @@ summary2 summary2 summary2 ",
],
"flex": 0,
"gravity": "top",
"maxLines": 6,
"maxLines": 12,
"type": "text",
"weight": "regular",
"wrap": true,
},
],
"layout": "vertical",
"margin": "none",
"spacing": "none",
"type": "box",
},
"direction": "ltr",
Expand All @@ -837,7 +815,7 @@ summary2 summary2 summary2 ",
Object {
"action": Object {
"data": "{\\"input\\":\\"AVvY-yizyCdS-nWhuYGB\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
"displayText": "I choose “https://www.youtube.co...”",
"displayText": "I choose ",
"label": "Choose this one",
"type": "postback",
},
Expand All @@ -851,26 +829,22 @@ summary2 summary2 summary2 ",
},
"header": Object {
"contents": Array [
Object {
"flex": 0,
"text": "😐",
"type": "text",
},
Object {
"color": "#AAAAAA",
"gravity": "center",
"size": "sm",
"text": "Looks 12% similar",
"text": "Looks 12% similar",
"type": "text",
"weight": "bold",
"wrap": true,
},
],
"layout": "horizontal",
"paddingBottom": "none",
"spacing": "md",
"paddingBottom": "md",
"spacing": "sm",
"type": "box",
},
"hero": undefined,
"type": "bubble",
},
Object {
Expand All @@ -879,7 +853,7 @@ summary2 summary2 summary2 ",
Object {
"color": "#ff7b7b",
"size": "sm",
"text": "(Words found in the hyperlink)",
"text": "(Text in the hyperlink)",
"type": "text",
"weight": "bold",
},
Expand Down Expand Up @@ -933,15 +907,13 @@ title2 title2 title2 ",
],
"flex": 0,
"gravity": "top",
"maxLines": 6,
"maxLines": 12,
"type": "text",
"weight": "regular",
"wrap": true,
},
],
"layout": "vertical",
"margin": "none",
"spacing": "none",
"type": "box",
},
"direction": "ltr",
Expand All @@ -950,7 +922,7 @@ title2 title2 title2 ",
Object {
"action": Object {
"data": "{\\"input\\":\\"AVvY-yizyCdS-nWhuYGA\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
"displayText": "I choose “http://www.chinatimes....”",
"displayText": "I choose ",
"label": "Choose this one",
"type": "postback",
},
Expand All @@ -964,26 +936,22 @@ title2 title2 title2 ",
},
"header": Object {
"contents": Array [
Object {
"flex": 0,
"text": "😐",
"type": "text",
},
Object {
"color": "#AAAAAA",
"gravity": "center",
"size": "sm",
"text": "Looks 0% similar",
"text": "Looks 0% similar",
"type": "text",
"weight": "bold",
"wrap": true,
},
],
"layout": "horizontal",
"paddingBottom": "none",
"spacing": "md",
"paddingBottom": "md",
"spacing": "sm",
"type": "box",
},
"hero": undefined,
"type": "bubble",
},
Object {
Expand Down
4 changes: 2 additions & 2 deletions src/webhook/handlers/initState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
createTextMessage,
createArticleSourceReply,
searchText,
createTextCarouselContents,
createSearchResultCarouselContents,
} from './utils';
import choosingArticle from './choosingArticle';

Expand Down Expand Up @@ -107,7 +107,7 @@ const initState = async ({
});
}

const articleOptions: FlexBubble[] = createTextCarouselContents(
const articleOptions: FlexBubble[] = createSearchResultCarouselContents(
result.edges,
context.sessionId
);
Expand Down
6 changes: 3 additions & 3 deletions src/webhook/handlers/processMedia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from 'ttag';
import type { Message, FlexMessage } from '@line/bot-sdk';
import type { FlexMessage } from '@line/bot-sdk';

import { Context, CooccurredMessage } from 'src/types/chatbotState';
import ga from 'src/lib/ga';
Expand All @@ -11,7 +11,7 @@ import {
createTextMessage,
createAskArticleSubmissionConsentReply,
searchMedia,
createMediaCarouselContents,
createSearchResultCarouselContents,
} from './utils';
import choosingArticle from './choosingArticle';

Expand Down Expand Up @@ -69,7 +69,7 @@ export default async function (message: CooccurredMessage, userId: string) {
});
}

const articleOptions = createMediaCarouselContents(
const articleOptions = createSearchResultCarouselContents(
result.edges,
context.sessionId
);
Expand Down
Loading

0 comments on commit 2c3e500

Please sign in to comment.