【问题标题】:How to send extra data in DialogFlow v2?如何在 DialogFlow v2 中发送额外数据?
【发布时间】:2018-07-31 14:16:58
【问题描述】:

如何在使用某些 SDK 调用 DialogFlow 时向其发送额外数据?
我知道在 v1 中,originalRequest.data 用于此目的。

基本上我想从网站会话中发送用户名、手机号码等并将其传递给 DialogFlow,以便我可以在 webhook 中获取它并执行一些操作。

我正在使用下面的代码来调用 DialogFlow:

import dialogflow

def detect_intent_texts(text, session_id):

    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(project_id, session_id)

    text_input = dialogflow.types.TextInput(
        text=text, language_code=language_code)

    query_input = dialogflow.types.QueryInput(text=text_input)

    response = session_client.detect_intent(
        session=session, query_input=query_input)

    return response.query_result.fulfillment_text


detect_intent_texts('hello how are you', 'some_session_id')

【问题讨论】:

    标签: chatbot dialogflow-es


    【解决方案1】:

    您需要在上下文中设置参数。

    • 创建上下文
    • 添加参数
    • 在下一次交互中提取上下文和参数。

    在 JSON 中,它看起来像这样

    {  
      "fulfillmentText":"This is a text response",
      "fulfillmentMessages":[  ],
      "source":"example.com",
      "payload":{  
        "google":{  },
        "facebook":{  },
        "slack":{  }
      },
      "outputContexts":[  
        {  
          "name":"context name",
          "lifespanCount":5,
          "parameters":{  
            "param":"param value"
          }
        }
      ],
      "followupEventInput":{  }
    }
    

    您可以在dialogflow-python-client 中使用create_context 看看如何在python 中完成它

    【讨论】:

      猜你喜欢
      • 2018-05-15
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-01-07
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多