我想发个短信
var number = '**********'
sendText: function(phone, callback) {
// maybe needs a .then() ?
var formattedPhone = Phone.format(Phone.parse(phone, 'US'), 'International_plaintext')
var messageBody = 'test'
client.sms.messages.create({
to: formattedPhone,
from: number,
body: messageBody
})
}, function(error, message) {
if (error) {
console.log("SMS ERROR sending to: " + formattedPhone)
callback(error)
} else {
console.log("SMS sent to: " + formattedPhone)
callback(null, message)
}
}
它不会将错误或成功字符串打印到控制台--是Phone.format(Phone.parse())调用通过阻塞线程或其他方式导致的吗?
发布于 2017-05-22 06:18:38
你有语法错误。用于错误消息的回调函数位于大括号之外。
https://github.com/TwilioDevEd/api-snippets/blob/master/rest/messages/send-message/example-1.2.x.js
sendText: function(phone, callback) {
// maybe needs a .then() ?
var formattedPhone = Phone.format(Phone.parse(phone, 'US'), 'International_plaintext')
var messageBody = 'test';
client.sms.messages.create({
to: formattedPhone,
from: number,
body: messageBody
/*})*/ // remove this should be deleted
}, function(error, message) {
if (error) {
console.log("SMS ERROR sending to: " + formattedPhone)
callback(error)
} else {
console.log("SMS sent to: " + formattedPhone)
callback(null, message)
}
});
}https://stackoverflow.com/questions/44105685
复制相似问题