diff --git a/src/webhook/handlers/__tests__/__snapshots__/singleUserHandler.test.ts.snap b/src/webhook/handlers/__tests__/__snapshots__/singleUserHandler.test.ts.snap index fced6c33..82a43b6a 100644 --- a/src/webhook/handlers/__tests__/__snapshots__/singleUserHandler.test.ts.snap +++ b/src/webhook/handlers/__tests__/__snapshots__/singleUserHandler.test.ts.snap @@ -253,6 +253,19 @@ Array [ ], "type": "carousel", }, + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "type": "flex", }, ], diff --git a/src/webhook/handlers/__tests__/singleUserHandler.test.ts b/src/webhook/handlers/__tests__/singleUserHandler.test.ts index 792ac0d9..9ded1d22 100644 --- a/src/webhook/handlers/__tests__/singleUserHandler.test.ts +++ b/src/webhook/handlers/__tests__/singleUserHandler.test.ts @@ -231,6 +231,19 @@ it('handles postbacks w/ LegacyContext', async () => { Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "Postback results here", "type": "text", }, @@ -275,6 +288,19 @@ it('rejects outdated postback events', async () => { Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "🚧 You are currently searching for another message, buttons from previous search sessions do not work now.", "type": "text", }, @@ -354,6 +380,19 @@ it('forwards to CHOOSING_ARTICLE when VIEW_ARTICLE_PREFIX is sent', async () => Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "Choosing article resp", "type": "text", }, @@ -413,6 +452,19 @@ it('shows reply list when article URL is sent', async () => { Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "Choosing article resp", "type": "text", }, @@ -493,6 +545,19 @@ it('Resets session on free-form input, triggers fast-forward', async () => { Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "Replies here", "type": "text", }, @@ -549,6 +614,19 @@ it('handles tutorial trigger from rich menu', async () => { Object { "messages": Array [ Object { + "quickReply": Object { + "items": Array [ + Object { + "action": Object { + "label": "來謠言惑眾獎投票吧!", + "type": "uri", + "uri": "https://www.mygopen.com/p/award_22.html", + }, + "imageUrl": "/static/img/mygopen-award-2024.png?cachebust=1", + "type": "action", + }, + ], + }, "text": "Tutorial here", "type": "text", }, diff --git a/src/webhook/handlers/singleUserHandler.ts b/src/webhook/handlers/singleUserHandler.ts index ec310bc5..65d4c6d7 100644 --- a/src/webhook/handlers/singleUserHandler.ts +++ b/src/webhook/handlers/singleUserHandler.ts @@ -140,6 +140,24 @@ const singleUserHandler = async ( }) ); + // Attach MyGoPen award as quick reply + const lastReply = result.replies[result.replies.length - 1]; + if (!lastReply.quickReply) { + lastReply.quickReply = { + items: [ + { + type: 'action', + imageUrl: `${process.env.RUMORS_LINE_BOT_URL}/static/img/mygopen-award-2024.png?cachebust=1`, + action: { + type: 'uri', + uri: 'https://www.mygopen.com/p/award_22.html', + label: '來謠言惑眾獎投票吧!', + }, + }, + ], + }; + } + // Send replies. Does not need to wait for lineClient's callbacks. // lineClient's callback does error handling by itself. // diff --git a/static/img/mygopen-award-2024.png b/static/img/mygopen-award-2024.png new file mode 100644 index 00000000..ae8560eb Binary files /dev/null and b/static/img/mygopen-award-2024.png differ