Skip to content

Commit

Permalink
feat(webhook): implement "no" on askingCooccurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Dec 27, 2023
1 parent 20d6f69 commit a670694
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ We use dimension `Message Source` (Custom Dimemsion1) to classify different even
- `UserInput` / `ArticleSearch` / `ArticleFoundButNoHit`
- When user provides source
- `UserInput` / `IsForwarded` / `Yes` | `No`
- When user specifies if the message comes from same person at same time (cooccurrence)
- `UserInput` / `IsCooccurrence` / `Yes` | `No`
- Matches one of Dialogflow intents
- `UserInput` / `ChatWithBot` / `<intent name>`
Expand Down
50 changes: 45 additions & 5 deletions src/webhook/handlers/askingCooccurrence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { t } from 'ttag';
import ga from 'src/lib/ga';
import { ChatbotPostbackHandler } from 'src/types/chatbotState';

import { POSTBACK_YES, POSTBACK_NO, ManipulationError } from './utils';
import {
POSTBACK_YES,
POSTBACK_NO,
ManipulationError,
createTextMessage,
} from './utils';

const inputSchema = z.enum([POSTBACK_NO, POSTBACK_YES]);

Expand All @@ -24,10 +29,45 @@ const askingCooccurence: ChatbotPostbackHandler = async ({
throw new ManipulationError(t`Please choose from provided options.`);
}

return {
context,
replies: [],
};
const visitor = ga(userId, state, `Batch: ${context.msgs.length} messages`);

switch (input) {
case POSTBACK_NO: {
visitor
.event({
ec: 'UserInput',
ea: 'IsCooccurrence',
el: 'No',
})
.send();
return {
context,
replies: [
createTextMessage({
text: t`Please send me the messages separately.`,
}),
],
};
}

case POSTBACK_YES: {
visitor
.event({
ec: 'UserInput',
ea: 'IsCooccurrence',
el: 'Yes',
})
.send();
return {
context,
replies: [],
};
}

default:
// exhaustive check
return input satisfies never;
}
};

export default askingCooccurence;

0 comments on commit a670694

Please sign in to comment.