简体   繁体   English

从dialogflow android sdk将有效负载发送到dialogflow

[英]sending payload to dialogflow from dialogflow android sdk

I am using Android client of dialogflow - https://github.com/dialogflow/dialogflow-android-client 我正在使用dialogflow的Android客户端-https: //github.com/dialogflow/dialogflow-android-client

I would like to know how to send payload, lat, lon from my android application to dialogflow. 我想知道如何将有效载荷,经纬度,经度从我的android应用程序发送到dialogflow。 some one could help on this? 有人可以帮上忙吗?

Update 更新

I am able to pass payload when I use the code like below, 使用以下代码时,我可以传递有效负载,

final AIRequest aiRequest = new AIRequest();
AIOriginalRequest aiO = new AIOriginalRequest(); 
HashMap<String, String> hm = new HashMap<String, String>(); 
hm.put("element_1", "8888"); 
hm.put("element_2", "abcd"); 
aiO.setData(hm); 
aiRequest.setOriginalRequest(aiO); 
aiRequest.setQuery("find Cheese");

and I am getting this in server as below, 我在下面的服务器中得到这个,

{
    "responseId": "ddsds-qwq-qwqwq-wqwqwq",
    "session": "<<session>>",
    "queryResult": {
        "languageCode": "en",
        "intentDetectionConfidence": "0.93",
        "allRequiredParamsPresent": "true",
        "parameters": {
            "item": "Cheese"
        },
        "fulfillmentMessages": [{
            "text": {
                "text": [""]
            }
        }],
        "queryText": "find Cheese",
        "intent": {
            "name": "<<session>>",
            "displayName": "item-req"
        }
    },
    "originalDetectIntentRequest": {
        "payload": {
            "element_2": "abcd",
            "element_1": "8888"
        }
    }
}

But as I am using AIService and using startListening method of that, I am not able to set the AIRequest and setOriginalRequest. 但是由于我正在使用AIService并使用其中的startListening方法,因此无法设置AIRequest和setOriginalRequest。 There is no way to set OriginalRequest if are using AIService and startListening. 如果正在使用AIService和startListening,则无法设置OriginalRequest。 The Dialogflow sdk is automatically doing this. Dialogflow SDK自动执行此操作。

Any one faced such situation or solved this? 有人遇到这种情况或解决了这个问题吗?

There is no direct way to pass such information other than using system entities. 除了使用系统实体之外,没有直接的方式来传递此类信息。 You may need to do a hack if you can't find an entity to extract your data. 如果找不到要提取数据的实体,则可能需要进行黑客入侵。 In my project, I wanted to send a custom UUID. 在我的项目中,我想发送一个自定义的UUID。 Now there was no specific system entity present in the Dialogflow which I could have used to extract the UUID so I used the simple approach of appending UUID to the Android response to Dialogflow and manually extracted it using || 现在Dialogflow中不存在可以用来提取UUID的特定系统实体,因此我使用了将UUID附加到对Dialogflow的Android响应并使用||手动提取的简单方法。 separator. 分隔器。

You could do the following: 您可以执行以下操作:

  • Identify a system entity that can be used to detect lat, lon in the message to Dialogflow. 标识可用于检测发送给Dialogflow的消息中的经纬度的系统实体。
  • Whatever the user response message is generated that you want to send to Dialogflow, programmatically append your lat, lon with it. 无论生成了什么您想要发送给Dialogflow的用户响应消息,都以编程方式附加到您的经纬度。 Like 'Hi! My name is Abhinav Tyagi. 77.0000 28.0000' 就像'Hi! My name is Abhinav Tyagi. 77.0000 28.0000' 'Hi! My name is Abhinav Tyagi. 77.0000 28.0000' 'Hi! My name is Abhinav Tyagi. 77.0000 28.0000' would be my generated message. 'Hi! My name is Abhinav Tyagi. 77.0000 28.0000'将是我生成的消息。
  • Train the Dialogflow Intent using this generated message and use the identified entity to extract the parameter in the webhook. 使用此生成的消息训练Dialogflow Intent,并使用标识的实体在webhook中提取参数。
  • If there is no entity, put the data in a JSON format. 如果没有实体,则以JSON格式放置数据。
  • Append this JSON at the end of the user response message separated by a separator like || 将此JSON附加在用户响应消息的末尾,并用||之类的分隔符分隔 like 'Hi! My name is Abhinav Tyagi.||{"lon":"77.0000", "lat":"28.0000"}' 就像'Hi! My name is Abhinav Tyagi.||{"lon":"77.0000", "lat":"28.0000"}' 'Hi! My name is Abhinav Tyagi.||{"lon":"77.0000", "lat":"28.0000"}' would be my generated message. 'Hi! My name is Abhinav Tyagi.||{"lon":"77.0000", "lat":"28.0000"}'将是我生成的消息。
  • Train the Dialogflow Intent using this generated message and variations. 使用此生成的消息和变体训练Dialogflow Intent。
  • In the webhook, get the input query from the request, split it using the separator and then simply parse your JSON to extract the lat and lon. 在webhook中,从请求中获取输入查询,使用分隔符将其拆分,然后只需解析JSON以提取lat和lon。

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

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