尝试访问队列成员时出错。
我已尝试过以下两种方法,以便在我错误地了解系统工作原理的情况下将成员添加到队列中。 (我开始使用Enqueue方法)
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Dial>
<Queue waitUrl="https://node.myserver.com:81/inbound/music">support</Queue>
</Dial>
</Response>
和
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Enqueue waitUrl="https://node.myserver.com:81/inbound/music">support</Enqueue>
</Response>
这两个似乎都可以用来添加对队列的调用和播放保持音乐
我还检查过以确保我有正确的队列SID
运行代码
client.queues.list(function(err, data) {
data.queues.forEach(function(queue) {
console.log(queue.friendlyName + ": " + queue.sid);
});
});
给我结果
支持:QUxxxxxxxxxxxxxxxx6
然而,当我在队列中调用并尝试使用来自https://www.twilio.com/docs/api/rest/member的twilio API页面的示例提取数据时
client.queues('QUxxxxxxxxxxxxxxxx6').members.list(function(err, data) {
data.members.forEach(function(member) {
console.log(member.Position);
});
});
我收到以下错误
GET /inbound/call/agent 200 39.997 ms - 73
/var/www/tcc/node_modules/twilio/node_modules/q/q.js:126
throw e;
^
TypeError: Cannot call method 'forEach' of undefined
at /var/www/tcc/routes/index.js:348:20
at /var/www/tcc/node_modules/twilio/node_modules/q/q.js:1920:17
at flush (/var/www/tcc/node_modules/twilio/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
17 Feb 14:02:42 - [nodemon] app crashed - waiting for file changes before starting...
答案 0 :(得分:0)
https://gist.github.com/StevenDStanton/f8c3d748e93466a7e4b8
var https = require('https');
var options = {
host: 'api.twilio.com',
port: 443,
path: '/2010-04-01/Accounts/' + sid + '/' + queuesid + '.json',
method: 'GET',
auth: sid + ":" + auth,
agent: false
};
var req = https.request(options, function(rex) {
rex.setEncoding('utf8');
rex.on('data', function (chunk) {
var obj = JSON.parse(chunk);
res.send(obj.current_size.toString());
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();