Skip to content

Commit

Permalink
feat: handling apple forms
Browse files Browse the repository at this point in the history
  • Loading branch information
JianChen-IT committed Dec 1, 2022
1 parent ca07f7f commit 4059284
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/botonic-core/src/models/events/botonic-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PostbackMessageEvent,
TextMessageEvent,
VideoMessageEvent,
FormMessageEvent,
} from './message'

export type BotonicEvent =
Expand All @@ -22,3 +23,4 @@ export type BotonicEvent =
| CarouselMessageEvent
| CustomMessageEvent
| ConnectionEvent
| FormMessageEvent
6 changes: 6 additions & 0 deletions packages/botonic-core/src/models/events/message/form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BotonicMessageEvent } from './message-event'

export interface FormMessageEvent extends BotonicMessageEvent {
form_title: string
form_answers: any
}
1 change: 1 addition & 0 deletions packages/botonic-core/src/models/events/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './missed'
export * from './postback'
export * from './replies'
export * from './text'
export * from './form'
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum MessageEventTypes {
POSTBACK = 'postback',
VIDEO = 'video',
MISSED = 'missed',
FORM = 'form',
/**
* TODO: contact, buttonmessage?, webchatsettings, whatsapp template
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/botonic-core/src/output-parser/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
parsePostback,
parseReplies,
parseText,
parseForm,
} from './parsers'

export class MessageParsingFactory {
Expand All @@ -31,6 +32,8 @@ export class MessageParsingFactory {
return parseCarousel(parsedMessage).parsed
case MessageEventTypes.CUSTOM:
return parseCustom(parseReplies(parsedMessage)).parsed
case MessageEventTypes.MISSED:
return parseForm(parsedMessage).parsed
case MessageEventTypes.MISSED:
return parseMissed(parsedMessage).parsed
}
Expand Down
14 changes: 13 additions & 1 deletion packages/botonic-core/src/output-parser/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LocationMessageEvent,
MissedMessageEvent,
PostbackMessageEvent,
FormMessageEvent,
Reply,
TextMessageEvent,
VideoMessageEvent,
Expand Down Expand Up @@ -128,7 +129,6 @@ export const parseText: ParseFunction<TextMessageEvent> = args => {
}

// POSTBACK

export const parsePostback: ParseFunction<PostbackMessageEvent> = args => {
return {
toParse: args.toParse,
Expand Down Expand Up @@ -211,3 +211,15 @@ export const parseMissed: ParseFunction<MissedMessageEvent> = args => {
},
}
}

// FORM
export const parseForm: ParseFunction<FormMessageEvent> = args => {
return {
toParse: args.toParse,
parsed: {
...args.parsed,
form_title: args.toParse.form_title,
form_answers: args.toParse.form_answers,
},
}
}

0 comments on commit 4059284

Please sign in to comment.