Javascript Meteor Twilio捷运包
快速提问(我希望)-我正在尝试使用Meteor Twilio软件包(“mrt添加Twilio”)从我的应用程序发送短信 一切都设置正确(我在文档中提到的那一刻就预装了),我想。。。然而,当我的代码在事件处理程序中运行时,我得到了一个“Twilio未定义”错误 大概这与包“需要”NPM包代码的方式有关?还有其他人面对过吗Javascript Meteor Twilio捷运包,javascript,node.js,meteor,twilio,Javascript,Node.js,Meteor,Twilio,快速提问(我希望)-我正在尝试使用Meteor Twilio软件包(“mrt添加Twilio”)从我的应用程序发送短信 一切都设置正确(我在文档中提到的那一刻就预装了),我想。。。然而,当我的代码在事件处理程序中运行时,我得到了一个“Twilio未定义”错误 大概这与包“需要”NPM包代码的方式有关?还有其他人面对过吗 Template.registration.events({ 'click #registerButton': function (e) { e.preventDef
Template.registration.events({
'click #registerButton': function (e) {
e.preventDefault();
var accountSid = 'AC758eaf30370ee2ba8b64f64ce19769c8';
var authToken = 'f8a0ee4560d3368a461e1f751b98fd90';
twilio = Twilio(accountSid, authToken); //this appears to be the issue
twilio.sendSms({
to:'+966533444837',
from: '+18654072438',
body: 'Hi this is a test from Twilio.'
}, function(err, responseData) {
if (!err) {
console.log(err)
}
});
}
});
您使用的代码仅在服务器端运行。您需要将其与方法/调用接口 服务器端:
Meteor.methods({
sendsms:function(param1, param2..) {
var accountSid = 'AC758eaf30370ee2ba8b64f64ce19769c8';
var authToken = 'f8a0ee4560d3368a461e1f751b98fd90';
twilio = Twilio(accountSid, authToken); //this appears to be the issue
twilio.sendSms({
to:'+966533444837',
from: '+18654072438',
body: 'Hi this is a test from Twilio.'
}, function(err, responseData) {
if (!err) {
console.log(err)
}
});
}
});
然后在客户机上
Meteor.call("sendsms", "something", "something");
您可能需要考虑使用同步代码或将<代码> TWILIO .SDENSMS 在流星.Y.WrasAsYNC
中,以在客户端返回结果。
Meteor.methods({
sendsms:function(param1, param2..) {
var accountSid = 'AC758eaf30370ee2ba8b64f64ce19769c8';
var authToken = 'f8a0ee4560d3368a461e1f751b98fd90';
twilio = Twilio(accountSid, authToken); //this appears to be the issue
twilio.sendSms({
to:'+966533444837',
from: '+18654072438',
body: 'Hi this is a test from Twilio.'
}, function(err, responseData) {
if (!err) {
console.log(err)
}
});
}
});
然后在客户机上
Meteor.call("sendsms", "something", "something");
您可能需要考虑使用同步代码或将<代码> TWILIO .SDENSMS 在流星> .WrasaSycNy/Code >中以在客户端返回结果。