我使用twilio節點發送短信。但我得到的錯誤:twilio發送短信不工作在流星
sendSms is not defined
這裏是服務器文件夾內我twilio文件:
import twilio from "twilio";
sms = {
accountSid: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
authToken: "your_auth_token"
};
const client = new twilio(sms.accountSid, sms.authToken);
console.log('client twilio *********** ',client)
sendSms=(phoneNum,randomNum)=> {
client
.sendSms({
body: "MicroTM one time password:" + randomNum,
to: phoneNum,
from: "+16062631146"
})
.then((message, err) => {
if (!err) {
console.log(message);
} else {
console.log(err);
}
});
}
現在,當我安慰twilio,我無法找到sendSms功能。 下面是日誌:
client twilio *********** Twilio {
I20170813-08:14:44.200(5.5)? username: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
I20170813-08:14:44.201(5.5)? password: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
I20170813-08:14:44.202(5.5)? accountSid: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
I20170813-08:14:44.204(5.5)? httpClient: {},
I20170813-08:14:44.204(5.5)? region: undefined,
I20170813-08:14:44.205(5.5)? _accounts: undefined,
I20170813-08:14:44.206(5.5)? _api: undefined,
I20170813-08:14:44.207(5.5)? _chat: undefined,
I20170813-08:14:44.208(5.5)? _fax: undefined,
I20170813-08:14:44.209(5.5)? _ipMessaging: undefined,
I20170813-08:14:44.209(5.5)? _lookups: undefined,
I20170813-08:14:44.210(5.5)? _monitor: undefined,
I20170813-08:14:44.210(5.5)? _notify: undefined,
I20170813-08:14:44.211(5.5)? _preview: undefined,
I20170813-08:14:44.211(5.5)? _pricing: undefined,
I20170813-08:14:44.212(5.5)? _taskrouter: undefined,
I20170813-08:14:44.212(5.5)? _trunking: undefined,
I20170813-08:14:44.212(5.5)? _video: undefined,
I20170813-08:14:44.213(5.5)? _messaging: undefined,
I20170813-08:14:44.213(5.5)? _wireless: undefined,
I20170813-08:14:44.214(5.5)? _sync: undefined }
這裏是我的package.json文件:
{
"name": "MicroTM",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"babel-runtime": "^6.20.0",
"bcrypt": "^1.0.2",
"busboy": "^0.2.14",
"fibers": "^2.0.0",
"lodash": "^4.17.4",
"meteor-node-stubs": "~0.2.4",
"moment": "^2.18.1",
"twilio": "^3.6.2"
}
}
,因爲我無法找到與twilio API的任何問題,可能有一些問題與的package.json文件。
編輯:
這裏是我的客戶端,我叫的發送短信功能:
Template.register.events({
'submit form': function(event) {
event.preventDefault();
let fullName = event.target.fullName.value,
phoneNum = event.target.phoneNum.value,
email = event.target.emailsignup.value,
password = event.target.passwordsignup.value,
confirmPass = event.target.passwordsignup_confirm.value;
console.log(phoneNum,email,password,confirmPass);
let randomNum = Math.floor(1000 + Math.random() * 9000);
let data = {
fullName: fullName,
phoneNum: phoneNum,
email:email,
password:password,
confirmPass:confirmPass,
otp:randomNum,
isVerified: false,
createdAt: Date.now()
};
if(password != confirmPass){
swal({
title: 'passwords are not matching!',
})
}
else{
Meteor.call('registerUser',data,function (err,res) {
if(!err){
//console.log('inside result ******* ',data)
sendSms(data.phoneNum,randomNum);
Router.go('verify')
}
else{
console.log('error ******* ', err)
}
})
}
}
})
確保客戶端可用的功能 –
如何在客戶端調用服務器功能? – wrangler
你的意思是我應該把發送短信功能的地方都可以訪問客戶端以及服務器 –