How to write this Fulfillment codes(including output)?

旧巷老猫 提交于 2019-12-13 03:51:59

问题


First of all, I tried to write how to save users input data to google sheet after developing the simple codes. It's able to work. Thank Mr.Master for providing this tutorial(Below the link).

Reference Mr.Master: https://www.youtube.com/watch?v=huwUpJZsTok

Next, I bumped into the problem below the code. I didn't know how to write it in Fulfillment. Could someone realize it to teach me?

Tool: Dialogflow, Google sheet, Firebase.

Theme: Order process

I tried to write Forhere() there. However, it didn't work.(First code)

function Forhere(agent){
    const{
      forhere, howmanypeople, whattime, namelist
    } = agent.parameters;
    const data1 = [{
      Forhere: forhere,
      HowManyPeople: howmanypeople,
      Time: whattime,
      Name: namelist
    }];
    axios.post('......', data1);
  }





{/*....This code is a result of test(second one)
  "responseId": "d0f44937-e58a-4b71-b6dc-ec2d6c39337b-f308a5c4",
  "queryResult": {
    "queryText": "黃大哥",
    "parameters": {
      "forhere": [
        "內用"
      ],
      "howmanypeople": [
        2
      ],
      "whattime": [
        **{
          "date_time": "2019-09-19T14:00:00+08:00"
        }**
      ],
      "namelist": [
        "黃大哥"
      ]
    },
    "allRequiredParamsPresent": true,
    "outputContexts": [
      {
        "name": "projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere",
        "lifespanCount": 4,
        "parameters": {
          "howmanypeople": [
            2
          ],
          "namelist.original": [
            "黃大哥"
          ],
          "howmanypeople.original": [
            "2"
          ],
          "forhere": [
            "內用"
          ],
          "whattime.original": [
            "明天下午2點"
          ],
          "welcome": "嗨",
          "whattime": [
            {
              "date_time": "2019-09-19T14:00:00+08:00"
            }
          ],
          "namelist": [
            "黃大哥"
          ],
          "welcome.original": "hi",
          "forhere.original": [
            "內用"
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85",
      "displayName": "ForHere"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "webhook_latency_ms": 4992
    },
    "languageCode": "zh-tw"
  },
  "webhookStatus": {
    "code": 4,
    "message": "Webhook call failed. Error: Request timeout."
  }
}

回答1:


You can use below code

let forhere= agent.parameters.forhere;
let howmanypeople= agent.parameters.howmanypeople;
let whattime= agent.parameters.whattime;
let namelist= agent.parameters.namelist;

then use this variables in your api call.




回答2:


To T.Ali:

Dialogflowfirebasefulfillment&Error message:

Although I think this error didn't show where these mistakes are.

Dialogflow Request body: {"responseId":"ab277bc6-3bcc-4c4b-9a94-192b9ecfb8af-f308a5c4","queryResult":{"queryText":"黃大哥","parameters":{"forhere":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"howmanypeople":3,"namelist":"黃大哥"},"allRequiredParamsPresent":true,"outputContexts":[{"name":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere","lifespanCount":4,"parameters":{"welcome":"嗨","welcome.original":"hi","forhere":"內用","forhere.original":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"whattime.original":"明天中午","howmanypeople":3,"howmanypeople.original":"3","namelist":"黃大哥","namelist.original":"黃大哥"}}],"intent":{"name":"projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85","displayName":"ForHere"},"intentDetectionConfidence":1,"languageCode":"zh-tw"},"originalDetectIntentRequest":{"payload":{}},"session":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d"}

Error: No handler for requested intent
    at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:317:29)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:105:9)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

Furthermore, I've write below the code worked formally(input users data to google sheet). enter image description here



来源:https://stackoverflow.com/questions/57990846/how-to-write-this-fulfillment-codesincluding-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!