Skip to content

Commit 1379ece

Browse files
committed
feat: plugin-flow-builder return text messages instead of whatsapp messages when the provider is not whatsapp
1 parent ac1f212 commit 1379ece

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

packages/botonic-plugin-flow-builder/src/content-fields/flow-whatsapp-cta-url-button.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { WhatsappCTAUrlButton, WhatsappCTAUrlHeaderType } from '@botonic/react'
1+
import { isWhatsapp } from '@botonic/core'
2+
import {
3+
ActionRequest,
4+
Button,
5+
Text,
6+
WhatsappCTAUrlButton,
7+
WhatsappCTAUrlHeaderType,
8+
} from '@botonic/react'
29
import React from 'react'
310

411
import { FlowBuilderApi } from '../api'
@@ -103,7 +110,16 @@ export class FlowWhatsappCtaUrlButtonNode extends ContentFieldsBase {
103110
}
104111
}
105112

106-
toBotonic(id: string): JSX.Element {
113+
toBotonic(id: string, request: ActionRequest): JSX.Element {
114+
if (!isWhatsapp(request.session)) {
115+
return (
116+
<Text>
117+
{this.text}
118+
<Button url={this.url}>{this.displayText}</Button>
119+
</Text>
120+
)
121+
}
122+
107123
if (
108124
this.headerType === WhatsappCTAUrlHeaderType.Image &&
109125
this.headerImage

packages/botonic-plugin-flow-builder/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { WhatsappButtonList } from '@botonic/react'
1+
import { isWhatsapp } from '@botonic/core'
2+
import { ActionRequest, Button, Text, WhatsappButtonList } from '@botonic/react'
23
import React from 'react'
34

45
import { FlowBuilderApi } from '../../api'
@@ -33,7 +34,23 @@ export class FlowWhatsappButtonList extends ContentFieldsBase {
3334
return newWhatsappButtonList
3435
}
3536

36-
toBotonic(id: string): JSX.Element {
37+
toBotonic(id: string, request: ActionRequest): JSX.Element {
38+
if (!isWhatsapp(request.session)) {
39+
const rows = this.sections.flatMap(section => section.rows)
40+
const buttons = rows.map(row => (
41+
<Button key={row.id} payload={row.id}>
42+
{row.title}
43+
</Button>
44+
))
45+
46+
return (
47+
<Text>
48+
{this.text}
49+
{buttons}
50+
</Text>
51+
)
52+
}
53+
3754
return (
3855
<WhatsappButtonList
3956
key={id}

0 commit comments

Comments
 (0)