Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add quickreply for mygopen award #390

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading