我想使用node.js代码将SMS发送给多个用户。要遵循的步骤是什么?我有点经验将短信发送给单个用户。但我不知道如何将短信发送给多个用户。我已附上代码以向单个用户发送SMS。 但在6个月之前,这些代码工作正常。但现在它不起作用。任何人都可以为这两个问题提供解决方案吗?
for line in $(cat linenumbers.txt); do
eline=$((${line}+3))
sed -i "Xs,(X+3)s/.*/REPLACEMENT/" filename.txt
done
答案 0 :(得分:0)
如果您想在使用Promise.all
的同时发送多条消息。我已经用我认为适合你的东西更新你的代码我使用bluebird.js创建它,因为我熟悉它并且它有kickass工具。
三:
var accountSid = 'cnsjs'; // Your Account SID from www.twilio.com/console
var authToken = 'chdcbhh'; // Your Auth Token from www.twilio.com/console
var Promise = require('bluebird');
var twilio = require('twilio');
var client = new twilio(accountSid, authToken);
var promises = [];
// add all the different send promises to this array like following
promises.push(
client.messages.create({
body: 'Hello hai I am vignesh Ravi . I sent the message from twilio account',
to: '+121331161616', // Text this number
from: '+18597401144' // From a valid Twilio number
})
)
var result = {
sent: [],
failed: []
};
var finalPromise = Promise.all(promises.map(function (p) {
return Promise.resolve(p).reflect(); // resolve will convert it to bluebird promise and reflect will make it always successful
})).each(function (inspection) {
if (inspection.isFulfilled()) { //this means the send was successful
result.sent.push(inspection.value());
} else { //this means there was an error
result.failed.push(inspection.reason());
}
}).then(function () {
return result;
})
finalPromise.then(function (res) {
console.log(JSON.stringify(res))
})
你可能需要在它开始工作之前稍微修改一下代码
修改强>
我对代码做了一些小改动,我最后称之为集体承诺。尝试一下,让我知道它是否有效