【发布时间】:2019-12-27 02:33:15
【问题描述】:
我正在尝试通过 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" });
});
});
【问题讨论】:
标签: node.js twilio twilio-studio