首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >语音-怎么用?

语音-怎么用?
EN

Stack Overflow用户
提问于 2017-05-22 06:06:49
回答 1查看 131关注 0票数 0

我想发个短信

代码语言:javascript
复制
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())调用通过阻塞线程或其他方式导致的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-22 06:18:38

你有语法错误。用于错误消息的回调函数位于大括号之外。

https://github.com/TwilioDevEd/api-snippets/blob/master/rest/messages/send-message/example-1.2.x.js

代码语言:javascript
复制
 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)
            }
        });
  }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44105685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档