【发布时间】:2018-04-04 17:44:56
【问题描述】:
我正在检查 twilio 文档上的 this 示例(v2.x 但 v3.x 也类似,我的问题不会改变)。
// This example uses JavaScript language features present in Node.js 6+
'use strict';
const express = require('express');
const twilio = require('twilio');
const urlencoded = require('body-parser').urlencoded;
let app = express();
// Parse incoming POST params with Express middleware
app.use(urlencoded({ extended: false }));
// Create a route that will handle Twilio webhook requests, sent as an
// HTTP POST to /voice in our application
app.post('/voice', (request, response) => {
// Use the Twilio Node.js SDK to build an XML response
let twiml = new twilio.TwimlResponse();
// Use the <Gather> verb to collect user input
twiml.gather({ numDigits: 1 }, (gatherNode) => {
gatherNode.say('For sales, press 1. For support, press 2.');
});
// If the user doesn't enter input, loop
twiml.redirect('/voice');
// Render the response as XML in reply to the webhook request
response.type('text/xml');
response.send(twiml.toString());
});
// Create an HTTP server and listen for requests on port 3000
app.listen(3000);
那么下面是阻塞的片段吗?
twiml.gather({ numDigits: 1 }, (gatherNode) => {
gatherNode.say('For sales, press 1. For support, press 2.');
});
如果是,那么假设用户输入了一些东西,然后我们移动到
twiml.redirect('/voice');
其他语句依次执行。
但是如果它是非阻塞的,那么/voice 端点会立即被调用,并且这会在一个无限循环中继续。
我想知道流程是如何工作的。
编辑:
混乱似乎是由这条评论引起的
// If the user doesn't enter input, loop
如果用户输入了一些东西,那么twiml.redirect('/voice') 也会被调用。我不确定该代码如何正常工作?
【问题讨论】:
标签: node.js twilio twilio-twiml