通过 twillio 使用 dialogflow fullfilment 发送短信失败

问题描述 投票:0回答:1

我必须使用 SMS 将我在 dialogflow 上工作的聊天机器人的信息分享给人类团队。 我正在使用 fullfilment 触发 twilio 使用我的 twilio 号码向团队电话号码发送短信。

代码如下

'use strict';
 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const accountSid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; 
const authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const twilio = require('twilio')(accountSid, authToken);

function enviarmensagem(usuario){
    // Configurações da transmissão
const client = new twilio(accountSid, authToken);
    client.messages
      .create({
          body: 'Teste OK',
          to: '+55XXXXXXXXXX',  // Envie uma mensagem a esse número
          from: '+1XXXXXXXXXXX' // Através do meu número Twilio
      })
     .then((message) => console.log(message.sid));
}
  
// Criação da Função no Firebase
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {

  // Definição do objeto controlador do 'agent'
  const agent = new WebhookClient({ request, response });

 // 'Handler' para enviar mensagem
  function enviarmensagem(agent) {
    agent.add('Mensagem enviada');
    enviarmensagem(agent.session);
  }
  
  // Executar a função adequada de acordo com a Intent recebida
  let intentMap = new Map();
  intentMap.set('Teste mensagem', enviarmensagem);

  try{
    agent.handleRequest(intentMap);
  }
  catch(e){
      console.log(e);
  }
});

PACKAGE.JSON

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "lint": "semistandard --fix \"**/*.js\"",
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.6.1",
    "twilio": "^3.29.2",
    "nodemailer": "^4.7.0"
  }
}

但是它返回以下 Fullfilment 状态

Webhook 调用失败。错误:DEADLINE_EXCEEDED,状态:URL_TIMEOUT,原因:TIMEOUT_WEB。

部署工作没有错误。

有人能帮我找出我的错误在哪里吗?

twilio sms dialogflow-es twilio-api dialogflow-es-fulfillment
1个回答
0
投票

函数需要返回一些东西才能完成 webhook 调用。请参阅 文档,了解什么会被归类为 ok 响应

© www.soinside.com 2019 - 2024. All rights reserved.