2017-03-03 108 views
1

所以我正在等待列表类型的应用程序。当用户将他们的信息提交给列表(使用autoform)时,他们应该通过Twilio服务发送信息。如何获得提交mongodb和流星变量

我目前有twilio硬编码的变量工作

方法发送短信

Meteor.methods({ 
sendSMS: function (phoneNumber) { 
    var authToken = 'token value here'; 
    var accountSid = 'sid value here'; 
    twilio = Twilio(accountSid, authToken); 
    twilio.sendSms({ 
     to: phoneNumber, // Any number Twilio can deliver to 
     from: '+18.....', // A number you bought from Twilio and can use for outbound communication 
     body: 'You have been added to the waitlist' // body of the SMS message 
    }, function (err, responseData) { //this function is executed when a response is received from Twilio 
     if (!err) { // "err" is an error received during the request, if any 
      // "responseData" is a JavaScript object containing data received from Twilio. 
      // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript): 
      // http://www.twilio.com/docs/api/rest/sending-sms#example-1 
      console.log(responseData.from); // outputs "+14506667788" 
      console.log(responseData.body); // outputs "word to your mother." 
     } 
    }); 
} 
}); 

这里是我用硬编码数量的工作情况:

Template.home.events({ 
    "submit #student-form": function(event) { 
     event.preventDefault(); 
     var phoneNumber = '+18.....'; 
     Meteor.call("sendSMS", phoneNumber); 
     // alert("You have been added to the WaitList"); 
     swal("Success!", "You have been added to the WaitList", "success") 
    } 
}); 

我quickform

  {{>quickForm id="student-form" collection="Students" type="insert" template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9"}} 

我想知道的是,如何获取刚刚提交到mongodb集合中的电话号码值,以便我可以使用twilio将消息发送到特定的电话号码?

+0

刚刚发现这个链接,解决问题 [here](http://stackoverflow.com/questions/29458095/find-value-in-meteor-mongo) –

+0

这应该得到的文本框的值: ' var phoneNumber = $('。classOfTextFieldWithPhoneNumber')。val();' 不知道如何适应这个quickform – janjackson

回答

0

OP在这里找到了答案:Find Value in Meteor Mongo

如果你正在寻找检索字段出返回文档, 可以指定为使用多领域的选项:

database.findOne({}, {sort: {'timeStamp' : -1}, limit:1, fields: {'myField': 1, _id: 0}) 

那将以如下格式检索对象:

{'myField': 'value of myField'}