Skip to content

Commit

Permalink
Merge pull request #390 from cofacts/mygopen-quickreply
Browse files Browse the repository at this point in the history
feat: add quickreply for mygopen award
  • Loading branch information
MrOrz authored Apr 6, 2024
2 parents c680acb + 9ddcc0d commit b785e64
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
Expand Down
78 changes: 78 additions & 0 deletions src/webhook/handlers/__tests__/singleUserHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down
18 changes: 18 additions & 0 deletions src/webhook/handlers/singleUserHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
Binary file added static/img/mygopen-award-2024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b785e64

Please sign in to comment.