2016-12-03 191 views
1

我想讓Twilio與我們的解析服務器集成,我知道如何發送消息給人,但我感到困惑的是你如何處理對解析服務器的響應。我需要使用傳入號碼來處理(僅一次)更改Parse中的字段。Twillio約會系統解析

我該如何處理我的服務器?

回答

0

Twilio開發者傳道這裏。

當有人向您提供的URL發送SMS消息到您的Twilio號碼Twilio will make an HTTP request。您可以在編輯your phone numbers之一時設置該URL。然後您需要創建一個可處理該傳入HTTP請求的應用程序。據我所知,解析服務器是基於Express的。所以你可以關注this guide which takes you through setting up a server to receive and then reply to an incoming SMS message with Node.js and Express

更具體地來分析,如果從語法分析服務器項目中使用的示例代碼,你需要做的是這樣的:

var express = require('express'); 
var ParseServer = require('parse-server').ParseServer; 
var app = express(); 

var api = new ParseServer({ 
    databaseURI: 'mongodb://localhost:27017/dev', // Connection string for your MongoDB database 
    cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code 
    appId: 'myAppId', 
    masterKey: 'myMasterKey', // Keep this key secret! 
    fileKey: 'optionalFileKey', 
    serverURL: 'http://localhost:1337/parse' // Don't forget to change to https if needed 
}); 

// Serve the Parse API on the /parse URL prefix 
app.use('/parse', api); 

// Receive incoming Twilio SMS messages 
app.post('/messages', function(req, res) { 
    console.log(req.body.Body); 
    // do something 
    // send an empty response to Twilio 
    res.send("<Response />"); 
}); 

app.listen(1337, function() { 
    console.log('parse-server-example running on port 1337.'); 
}); 

讓我知道,如果這有助於在所有。

+0

是的,這確實有幫助!調用雲計算函數還是僅僅實際執行我需要在同一個地方執行的內容,以便聲明app.post會更容易些?只考慮組織和清晰點。 我會基本上只使用JavaScript SDK進行解析來執行我需要執行的操作嗎? – trever

+0

哦,呃,我不確定如何最好地佈置一個Parse應用程序,如果你想保持它作爲一個雲功能,那麼它可以工作,或者你可以使用普通的Express方法。這取決於您如何組織代碼的其餘部分。 – philnash