简体   繁体   English

如何处理对话流中自定义有效负载的答案?

[英]How to handle the answer of a custom payload in dialogflow?

I have a bot that handles well the welcome intent using Dialogflow for Slack.我有一个使用 Dialogflow for Slack 处理欢迎意图的机器人。 However I don't know how to deal with the answer to the welcome intent to fire the second post.但是,我不知道如何处理对解雇第二个帖子的welcome intent的答案。 Indeed, the welcome intent , which outputs a await_answer1 context, shows the following template in json:实际上,输出await_answer1上下文的welcome intent在 json 中显示了以下模板:

{
  "slack": {
    "text": "",
    "attachments": [
      {
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "*How have you been feeling?* Poll by <fakeLink.toUser.com|Mihailo>"
            }
          },
          {
            "type": "divider"
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ":tired_face: *I’ve been feeling more exasperated and hopeless*"
            },
            "accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "1"
            }
          },
          {
            "accessory": {
              "value": "2",
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              }
            },
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ":expressionless: *Generally, less freaked out than other people*"
            }
          },
          {
            "accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "3"
            },
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ":relieved: *More calm and hopeful*"
            }
          },
          {
            "type": "divider"
          },
        ]
      }
    ]
  }
}

And I would like to handle the answer.我想处理答案。 So I created an answer1 intent which takes the await_answer1 as an input context.所以我创建了一个answer1意图,它将await_answer1作为输入上下文。 The training phrases are the output of the above template: 1 , 2 , 3 , 4 , 5 .训练短语是上述模板的 output: 1 , 2 , 3 , 4 , 5 And the Default text response is Interesting!默认文本响应很Interesting! However after selecting the answer is the Fallback intent rather than answer1 .但是,选择答案后是Fallback intent而不是answer1 Therefore, how to handle thee answer of a custom payload in dialogflow?因此,如何在对话流中处理自定义有效负载的答案?

AngelDev answer AngelDev 回答

I tried to include block_id :我试图包括block_id

{
  "slack": {
    "text": "",
    "attachments": [
      {
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "*How have you been feeling?* Poll by <fakeLink.toUser.com|Mihailo>"
            }
          },
          {
            "type": "divider"
          },
          {
            "accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "1"
            },
            "type": "section",
            "block_id": "1",
            "text": {
              "type": "mrkdwn",
              "text": ":tired_face: *I’ve been feeling more exasperated and hopeless*"
            }
          },
          {
            "accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "2"
            },
            "type": "section",
            "block_id": "2",
            "text": {
              "type": "mrkdwn",
              "text": ":expressionless: *Generally, less freaked out than other people*"
            }
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ":relieved: *More calm and hopeful*"
            },
            "accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "3"
            }
          },
          {
            "type": "section",
            "block_id": "4",
            "text": {
              "type": "mrkdwn",
              "text": ":fearful: *More scared and panicked*"
            },
            "accessory": {
              "value": "4",
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              }
            }
          },
          {
            "type": "section",
            "block_id": "5", 
            "text": {
              "type": "mrkdwn",
              "text": ":open_mouth: *More surprised and baffled*"
            },
            "accessory": {
              "value": "5",
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              }
            }
          }
        ]
      }
    ]
  }
}

Yet when I click on the button the DialogFlow bot falls on the DefaultFallback intent rather than going to the answer1 intent that should handle the await_answer1 context.然而,当我单击按钮时,DialogFlow 机器人落在 DefaultFallback 意图上,而不是转到应处理await_answer1上下文的answer1意图。

I'm not completly sure why, but if you remove the output and input context, this setup works fine.我不完全确定为什么,但如果你删除 output 和输入上下文,这个设置工作正常。

在此处输入图像描述

These are the accessory properties I used, I only changed the value property and added those values as a example phrase to my intents.这些是我使用的附属属性,我只更改了value属性并将这些值作为示例短语添加到我的意图中。

"accessory": {
              "value": "First",
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              }
            },

"accessory": {
              "value": "Second",
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              }
            },

"accessory": {
              "type": "button",
              "text": {
                "emoji": true,
                "type": "plain_text",
                "text": "Vote"
              },
              "value": "Third"

If you are looking to build a very customized Slack experience it might be worth to investigate into the Slack API .如果您希望构建一个非常定制的 Slack 体验,可能值得研究Slack API OnClick events and other Slack specific events are currenty not supported from within the Dialogflow UI, but you can integrate it with code in a webhook and from there customize your conversation in greater detail. OnClick 事件和其他 Slack 特定事件目前在 Dialogflow UI 中不受支持,但您可以将其与webhook中的代码集成,并从那里更详细地自定义您的对话。

You must include a block_id in your custom payload in each element of the block arrangement and this value must be in the training phrases of your intention since when you receive an interaction you receive this block_id.您必须在块排列的每个元素的自定义有效负载中包含一个 block_id,并且此值必须在您的意图的训练短语中,因为当您收到交互时,您会收到此 block_id。 For example例如

  {
      "type": "section",
      "text": {
          "type": "mrkdwn",
          "text": "*How have you been feeling?* Poll by <fakeLink.toUser.com|Mihailo>"
        },
       block_id: "section_1"
     }

I hope it is what you are looking for but you can write to me to help you solve your doubts.我希望这是您正在寻找的东西,但是您可以写信给我以帮助您解决疑问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM