import { h, Component } from 'preact'; import {botman} from './../botman'; import { IButton, IMessage, IMessageTypeProps } from '../../typings'; import MessageType from "./messagetype"; export default class ButtonsType extends MessageType { render(props: IMessageTypeProps) { const message = props.message; const buttons = message.buttons.map((button) => { if (button.type === 'postback') { return
this.performAction(button)}> {button.title}
; } if (button.type === 'web_url') { return {button.title}; } }); return (
{message.text} {this.state.attachmentsVisible ? buttons : ''}
); } performAction(button: IButton) { botman.callAPI(button.payload, true, null, (msg: IMessage) => { this.state.attachmentsVisible = false; this.props.messageHandler({ text: msg.text, type: msg.type, actions: msg.actions, attachment: msg.attachment, additionalParameters: msg.additionalParameters, from: 'chatbot' }); }, null); } }