我正在研究 google hangout 聊天机器人,在机器人中添加了斜杠命令,触发以下对话框:
def dialog_response(event_message):
custom_params = [{'key': INTERACTIVE_BUTTON_PARAMETER_KEY,
'value': event_message}]
section = {"sections": [
{
"widgets":[
{
"image": {
"imageUrl": "https://source.unsplash.com/featured/320x180?nature&sig=1",
"altText": "Placeholder image"
}
},
{
"buttonList": {
"buttons": [
{
"text": "Button 2",
"onClick": {
"action": {
"function": respond_to_interactive_card_click(SHOW_CARDS_ACTION_BUTTON,custom_params)
}
}
}
]
},
"horizontalAlignment": "CENTER"
},
{
"selectionInput": {
"type": "DROPDOWN",
"label": "Dropdown",
"name": "select1",
"items": [
{
"text": "Choice 1",
"value": "1",
"selected": False
},
{
"text": "Choice 2",
"value": "2",
"selected": False
},
{
"text": "Choice 3",
"value": "3",
"selected": False
}
]
}
}
]
}
]
}
response = {
"action_response": {
"type": "DIALOG",
"dialog_action": {
"dialog": {
"body": section
}
}
}
}
print(response)
return response
由于之前对按钮的 onclick 事件处理一切正常,因此对话框无法加载此内容。需要弄清楚对话框的组件事件处理,我遵循了文档但无法真正理解
https://developers.google.com/chat/how-tos/bot-dialogs
#google-hangout #bot