Я развернул Google ChatBot. Я создал следующий виджет с 3 кнопками, методы
function testwidgetData()
{
var RESHEADER = {
header: {
title : 'ChatBot',
subtitle : 'Test widget',
imageUrl : 'https://sites.google.com/a/abc.jpg'
}
};
var widgets = [
{
textParagraph: {
text: '<b>Test widget</b>'
}
},
{
"keyValue": {
"content": 'Input one',
"contentMultiline": true,
"button": {
"textButton": {
"text": "One",
"onClick": {
action:
{
actionMethodName: 'testAction',
parameters: [{key: 'entities',value: "one"}]
}
}
}
}
}
},
{
"keyValue": {
"content": 'Input Two',
"contentMultiline": true,
"button": {
"textButton": {
"text": "Two",
"onClick": {
action:
{
actionMethodName: 'testAction2',
parameters: [{key: 'entities',value: "Two"}]
}
}
}
}
}
},
{
"keyValue": {
"content": 'Input Third',
"contentMultiline": true,
"button": {
"textButton": {
"text": "Third",
"onClick": {
action:
{
actionMethodName: 'testAction3',
parameters: [{key: 'entities',value: "Third"}]
}
}
}
}
}
}
];
return {
"actionResponse":{
"type": "NEW_MESSAGE"
},
cards: [RESHEADER, {
sections: [{
widgets: widgets
}]
}]
};
}
testAction
обрабатываются в onCardClick
, как показано ниже,
function onCardClick(event) {
if(event.action.actionMethodName === 'testAction')
{
return createUserInformationResponseWidget('Your selected option is : '+event.action.parameters[0].value);
}
else if(event.action.actionMethodName === 'testAction2')
{
return createUserInformationResponseWidget('Your selected option is2 : '+event.action.parameters[0].value);
}
else if(event.action.actionMethodName === 'testAction3')
{
return createUserInformationResponseWidget('Your selected option is3 : '+event.action.parameters[0].value);
}
}
createUserInformationResponseWidget
, как показано ниже
function createUserInformationResponseWidget(response)
{
var RESHEADER = {
header: {
title : 'Chatbot',
subtitle : 'Action Performed Successfully!!!',
imageUrl : 'https://sites.google.com/right-png-1.png'
}
};
var widgets = [{
textParagraph: {
text: '<b>'+response+'</b>'
}
}];
return {
cards: [RESHEADER, {
sections: [{
widgets: widgets
}]
}]
};
}
Мой вопрос: При нажатии кнопки действия я получаю ответное сообщение только для первой нажатой кнопки - другие операции выполняются без какого-либо успеха / ответа об ошибке. Если я сначала нажимаю кнопку «Три», а затем получаю ответ «3», «Один» и «Два» не работают, и наоборот для всех кнопок.