小编jon*_*ira的帖子

尝试将Twilio与Meteor一起使用,ReferenceError:Twilio未定义

为了序言,我对Meteor很新,之前从未使用过Twilio,所以我可能只是在某个地方犯了一个愚蠢的错误.

我正在使用这里找到的Twilio API绑定,并试图获得一个简单的代码片段,用于在Meteor.methods函数中发送SMS消息.这是事件触发器和方法功能:

if (Meteor.isClient) {
    Template.twilioPlayground.events({
        "click button": function() {
            Meteor.call("sendSMS");
        }
    });
}

Meteor.methods({
    sendSMS: function () {
        twilio = Twilio('i put my account sid here', 'and my auth token here');
        twilio.sendSms({
            to:'+7199634882', 
            from: '+17194530451', 
            body: 'This is a test'
        }, function(err, responseData) { //this function is executed when a response is received from Twilio
            if (!err) {
                console.log(responseData.from); // outputs "+14506667788"
                console.log(responseData.body); // outputs "word to your mother."
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

因此,当触发该事件时,我收到以下错误: …

javascript twilio npm meteor

3
推荐指数
1
解决办法
1247
查看次数

标签 统计

javascript ×1

meteor ×1

npm ×1

twilio ×1