diff --git a/README.md b/README.md index 67f10829..b08e8a6d 100644 --- a/README.md +++ b/README.md @@ -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` / `` diff --git a/src/webhook/handlers/askingCooccurrence.ts b/src/webhook/handlers/askingCooccurrence.ts index fe4a6693..17df1008 100644 --- a/src/webhook/handlers/askingCooccurrence.ts +++ b/src/webhook/handlers/askingCooccurrence.ts @@ -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]); @@ -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;