libphonejs - 如何使用它?
libphonejs - how to use it?
我收到了以下发送 SMS 的尝试
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()) 调用通过阻塞线程或其他原因引起的吗?
您有语法错误。错误消息的回调函数在大括号外。
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)
}
});
}
我收到了以下发送 SMS 的尝试
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()) 调用通过阻塞线程或其他原因引起的吗?
您有语法错误。错误消息的回调函数在大括号外。
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)
}
});
}