Javascript libphonejs-如何使用它?

Javascript libphonejs-如何使用它?,javascript,node.js,twilio,libphonenumber,Javascript,Node.js,Twilio,Libphonenumber,我有以下尝试发送短信 var number='***********' sendText:函数(电话、回拨){ //也许需要一个。那么()? var formattedPhone=Phone.format(Phone.parse(Phone,'US'),'International_plaintext') var messageBody='test' client.sms.messages.create({ 致:电话:, 发件人:号码:, 正文:messageBody }) },函数(错误,消

我有以下尝试发送短信

var number='***********'
sendText:函数(电话、回拨){
//也许需要一个。那么()?
var formattedPhone=Phone.format(Phone.parse(Phone,'US'),'International_plaintext')
var messageBody='test'
client.sms.messages.create({
致:电话:,
发件人:号码:,
正文:messageBody
})
},函数(错误,消息){
如果(错误){
console.log(“发送到:“+formattedPhone”的SMS错误)
回调(错误)
}否则{
console.log(“短信发送至:”+formattedPhone)
回调(空,消息)
}

}
您有语法错误。错误消息的回调函数在大括号外


你有语法错误。错误消息的回调函数在大括号外


数字变量是undefinedit,它只是一个全局代码段,它是无效的javascript语法。。。所以,
sendText
看起来应该是某个对象的属性,但您没有显示它-您如何调用
sendText
?实际上,再次查看代码,它是各种各样的错误,我很惊讶您在控制台中没有得到任何错误
sendtext:function(phone,callback){…},function(error,message){…}
看起来像是用手指在键盘上捣乱而产生的随机代码。exports={…,…,…}每个函数的语法有一个错位的
}
。你确定你的前端m8吗?数字变量是未定义的。这只是一个全局代码段。它是无效的javascript语法。。。所以,
sendText
看起来应该是某个对象的属性,但您没有显示它-您如何调用
sendText
?实际上,再次查看代码,它是各种各样的错误,我很惊讶您在控制台中没有得到任何错误
sendtext:function(phone,callback){…},function(error,message){…}
看起来像是用手指在键盘上捣乱而产生的随机代码。exports={…,…,…}每个函数的语法有一个错位的
}
。你确定你的前端是m8吗?你是一个神童,在我的代码库上看了一百万小时后很容易错过。你是一个神童,在我的代码库上看了一百万小时后很容易错过。
 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)
            }
        });
  }