meteorTwilio MRT包
快速的问题(我希望) – 我正在尝试使用Meteor Twilio软件包(“mrt add twilio”)从我的应用程序发送短信。
一切都设置正确(我预先安装Moment正如在文档中提到的),我认为…但是,当我的代码在事件处理程序中运行时,我得到“Twilio未定义”错误。
据推测,这是与包“需要”的NPM包代码的方式? 有没有其他人面对这个?
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.sendSms
包装到Meteor._wrapAsync
以在客户端上获取结果。
- ExpressJS中的路由(“下一个”)是做什么的?
- 在stream节点js时写入一个wav文件
- 渲染EJS模板会抛出一个错误this.templateText.replace不是一个函数
- 如何避免使用dependency injection时使用types检查逻辑填充我的JavaScript代码?
- 电子浏览器的JavaScript错误
- 在nodejs和web浏览器中运行的javascript,关于variables的作用域
- 使用nodeJS检查其他域SSL证书
- 在nodejs中parsingchunked-encoded http响应的最好方法是什么?
- 用JStesting文件testing用Karma和Jasmine编译的TypeScript