我正在尝试通过 Node 中的 API 调用在 Twilio 上启动一个流程,但我似乎无法让它工作。该流程旨在在发送 API 请求时进行出站调用。尝试了几个我在网上看到的代码示例无济于事。我收到类似Cannot read property X of undefined
(见下文)的错误,但问题是我能够通过 API 调用向我的手机发起电话呼叫(不是流,只是一个呼叫),所以我知道 Twilio 客户端是连接的。
作品:
app.post('/call', (req, res) => {
client.calls
.create({
url: 'https://handler.twilio.com/twiml/PNxxxxxxxxxxxxxxxxxxxx',
to: '+1708xxxxxxx',
from: '+1312xxxxxxx'
})
.then((call, err) => {
if (err) { console.log(err) }
res.json({ success: "success" });
});
});
不工作:触发器Cannot read property 'v1' of undefined
app.post('/flow', (req, res) => {
client.studio.v1.flows('FWxxxxxxxxxxxxxxxxxxxx')
.fetch()
.then(flow => console.log("flow : ", flow));
不工作:触发器Cannot read property 'flows' of undefined
app.post('/flow', (req, res) => {
client.studio.flows('FWxxxxxxxxxxxxxxxxxxxx')
.executions
.create({
to: '+1847xxxxxxx',
from: '+1312xxxxxxx'
})
.then(function(execution) { console.log("sid : ", execution.sid); });
});
不工作:没有错误,只是没有任何反应
app.post('/flow', (req, res) => {
client.calls
.create({
url: 'https://studio.twilio.com/v1/Flows/FWxxxxxxxxxxxxxxxxxxxx/Executions',
to: '+1847xxxxxxx',
from: '+1312xxxxxxx'
})
.then((call, err) => {
if (err) { console.log("err : ", err) }
if (call) { console.log("call : ", call)}
res.json({ success: "success" });
});
});