簡體   English   中英

如何為對話流聊天機器人創建本地服務器?

[英]How to create a local server for dialogflow chatbot?

我正在嘗試使用node.js框架為 dialogflow bot 構建本地服務器,但無法建立一個。

我正在使用serveo.net作為隧道,因為ngrok不起作用,因為它被我的研究所阻止了。

我能夠啟動服務器,但無法從它獲得對 dialogflow 代理的響應。

'use strict';

const {WebhookClient} = require('dialogflow-fulfillment');

const express = require("express"); //express

const bodyParser = require("body-parser"); //body-parser

const app = express(); //app

app.use(bodyParser.json);

app.use(bodyParser.urlencoded({
    extended: true
  })
);

const WEBHOOK = 'webhook';

app.get('/', (req, res) => res.send('online'));

app.post('/webhook', express.json(), (request, respond) => {
  const agent = new WebhookClient({
    request,
    response
  });

  function webhookprocessing(request, response) {
    const agent = new WebhookClient(request, response);
    const action = agent.intent;
    if (action == WEBHOOK) {
      agent.add("My name is karthik");
    } else {
      agent.add("karthik");
    }
  }

  function welcome() {
    agent.add('Welcome to my agent!')
  }

  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set("webhook", webhookprocessing);

  agent.handleRequest(intentMap)
  //const agentPath =  agent.entitiesClient.projectAgentPath("master-bot-53dee");
  //console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  //console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
  //console.log("Server Hit");
});

app.listen(process.env.PORT || 5000);

編輯 1:我收到來自 google dialogflow 的請求,但我的本地服務器沒有發送響應。

edit2:dialogflow 從我的節點接收到的響應負載是

{
   "responseId":"efaf7898-74de-4727-bf2a-8eeb32ba570a-baaf0c1f",

   "queryResult":{

      "queryText":"1",

      "parameters":{

         "number":1

      },

      "allRequiredParamsPresent":true,

      "fulfillmentMessages":[
         {

            "text":{

               "text":[

                  ""

               ]
            }

         }

      ],

      "intent":{

         "name":"projects/master-bot-53dee/agent/intents/15b96d92-4adb-4657-8b15-ebdf7df180b4",

         "displayName":"webhook"
      },
      "intentDetectionConfidence":1,

      "diagnosticInfo":{

         "webhook_latency_ms":4991
      },

      "languageCode":"en"

   },

   "webhookStatus":{
      "code":4,
      "message":"Webhook call failed. Error: Request timeout."
   }
}

並且由 dialogflow 發送的請求有效負載是

{
   "responseId":"efaf7898-74de-4727-bf2a-8eeb32ba570a-baaf0c1f",
   "queryResult":{
      "queryText":"1",
      "parameters":{
         "number":1
      },
      "allRequiredParamsPresent":true,
      "fulfillmentMessages":[
         {
            "text":{
               "text":[
                  ""
               ]
            }
         }
      ],
      "intent":{
         "name":"projects/master-bot-53dee/agent/intents/15b96d92-4adb-4657-8b15-ebdf7df180b4",
         "displayName":"webhook"
      },
      "intentDetectionConfidence":1,
      "languageCode":"en"
   },
   "originalDetectIntentRequest":{
      "payload":{

      }
   },
   "session":"projects/master-bot-53dee/agent/sessions/d1205a66-9eda-d79c-7677-75eeb402e7e5"
}

dialogflow 發送的請求到達了我的隧道軟件創建的公共 URL,但沒有來自 localhost 的任何響應。

在此處輸入圖片說明

此圖像是我的控制台的屏幕截圖,其中我似乎收到了一個發布請求,但在 dialogflow 上沒有出現響應。

我已經使用這個 url 來引用 webhook url https://excedo.serveo.net/

在此處輸入圖片說明

app.post('/webhook', express.json(), (request, respond) => { // error name of the param doesn't match its usage

您正在使用響應作為參數並傳遞和使用響應的這一行。請將行更改為-

app.post('/webhook', express.json(), (request, response) => {

未在/webhook路徑調用/webhook因為 Dialogflow 中的配置告訴它 webhook 位於/ 如果您將其更改為https://excedo.serveo.net/webhook ,它將被正確路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM