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