Skip to content

Commit

Permalink
refactor(react): whatsappTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Aina Vendrell authored and Aina Vendrell committed Oct 5, 2020
1 parent 9664f95 commit ac83b54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/botonic-core/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const INPUT: {
CAROUSEL: 'carousel'
CUSTOM: 'custom'
WEBCHAT_SETTINGS: 'webchatsettings'
WHATSAPP_TEMPLATE: 'whatsapptemplate'
}

export type InputType =
Expand All @@ -40,6 +41,7 @@ export type InputType =
| typeof INPUT.CAROUSEL
| typeof INPUT.CUSTOM
| typeof INPUT.WEBCHAT_SETTINGS
| typeof INPUT.WHATSAPP_TEMPLATE

export interface Input {
type: InputType
Expand Down
1 change: 1 addition & 0 deletions packages/botonic-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export const INPUT = Object.freeze({
CAROUSEL: 'carousel',
CUSTOM: 'custom',
WEBCHAT_SETTINGS: 'webchatsettings',
WHATSAPP_TEMPLATE: 'whatsapptemplate',
})
29 changes: 14 additions & 15 deletions packages/botonic-react/src/components/whatsapp-template.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@ import { Message } from './message'
import { renderComponent } from '../utils'
import { INPUT } from '@botonic/core'

const serialize = whatsappTemplateProps => {
return { text: whatsappTemplateProps }
}

export const WhatsappTemplate = props => {
const renderBrowser = () => {
let params = ''
for (const param in props.parameters) {
params = params + " '" + props.parameters[param] + "', "
}
// Return a dummy message for browser
const message = `Template ${props.name} with namespace ${props.namespace} would be sent to the user.`
return (
<Message {...props} type={INPUT.TEXT}>
Template {props.name} would be send to the user with parameters:&quot;
{params} and namespace {props.namespace}
<Message json={serialize(message)} {...props} type={INPUT.TEXT}>
{message}
</Message>
)
}

const renderNode = () => {
let params = ''
for (const param in props.parameters) {
params = params + ', ' + props.parameters[param]
}
return (
<Message {...props} type={INPUT.TEXT}>
&[Fallback text]({props.namespace}, {props.name}
{params})
</Message>
<message
{...props}
header={props.header && JSON.stringify(props.header)}
body={props.body && JSON.stringify(props.body)}
footer={props.footer && JSON.stringify(props.footer)}
type={INPUT.WHATSAPP_TEMPLATE}
/>
)
}

Expand Down

0 comments on commit ac83b54

Please sign in to comment.