Я проверял это в документации Twilio (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')
. Я не уверен, как этот код вообще работает должным образом?