Dialogflow(通过Twilio发送短信)

时间:2018-05-29 18:21:01

标签: javascript node.js twilio dialogflow

我正在尝试从Dialogflow发送短信。 这就是我的全部内容:

    var accountSid = 'A**********************'; 
    var authToken = 'f**********************';   

    var twilio = require('twilio');
    var client = new twilio(accountSid, authToken);

    client.messages.create({
          body: 'Hello from me',
          to: '+1(phone-number)',  // Text this number
          from: '+1(phone-number)' // From a valid Twilio number
   })
  .then((message) => console.log(message.sid));

我想设置意图,以便触发短语并自动Bot发送短信(通知)。

1 个答案:

答案 0 :(得分:1)

You should use Dialogflow's fulfillment nodejs library. From the Quick Start sample, you can see how intent names are mapped to function handlers based on the intent map:

  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);

To send a text message, just add your SMS-sending code to a function and then map it to an intent name via the intentMap. Enable webhook fulfillment for this intent in Dialogflow's UI and the webhook will be called whenever the intent is matched.