Skip to content

Commit

Permalink
fix(webhook): askingArticleSource context args
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Dec 18, 2023
1 parent 37fea1d commit 0430693
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/webhook/handlers/askingArticleSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const inputSchema = z.enum([POSTBACK_NO, POSTBACK_YES]);
export type Input = z.infer<typeof inputSchema>;

const askingArticleSource: ChatbotPostbackHandler = async ({
data,
context,
postbackData: { state, input: postbackInput },
userId,
}) => {
Expand All @@ -36,11 +36,13 @@ const askingArticleSource: ChatbotPostbackHandler = async ({

let replies: Message[] = [];

const visitor = ga(
userId,
state,
'searchedText' in data ? data.searchedText : data.messageId
);
const firstMsg = context.msgs[0];
// istanbul ignore if
if (!firstMsg || firstMsg.type !== 'text') {
throw new Error('No message found in context'); // Never happens
}

const visitor = ga(userId, state, firstMsg.text);

switch (input) {
default: {
Expand Down Expand Up @@ -113,7 +115,7 @@ const askingArticleSource: ChatbotPostbackHandler = async ({
t`See Tutorial`,
TUTORIAL_STEPS.RICH_MENU,
TUTORIAL_STEPS.RICH_MENU,
data.sessionId,
context.sessionId,
'TUTORIAL'
),
style: 'primary',
Expand Down Expand Up @@ -185,7 +187,7 @@ const askingArticleSource: ChatbotPostbackHandler = async ({
createTextMessage({
text: t`Do you want someone to fact-check this message?`,
}),
createAskArticleSubmissionConsentReply(data.sessionId),
createAskArticleSubmissionConsentReply(context.sessionId),
];
visitor.event({
ec: 'UserInput',
Expand All @@ -196,7 +198,7 @@ const askingArticleSource: ChatbotPostbackHandler = async ({

visitor.send();

return { data, replies };
return { context, replies };
};

export default askingArticleSource;

0 comments on commit 0430693

Please sign in to comment.