Facebook Messenger API implementation in c# asp.net mvc app -


in node.js implementation

app.post('/webhook/', function(req, res) {   console.log("message received " + req.body); if(!req.body){     console.log("no request body found");     res.sendstatus(200);     return; }  messaging_events = req.body.entry[0].messaging; (i = 0; < messaging_events.length; i++) {     event = req.body.entry[0].messaging[i];     sender = event.sender.id;     console.log("sender " + event.sender + ", message " + event.message.text);     if (event.message && event.message.text) {         text = event.message.text;         // handle text message sender         sendtextmessage(sender, "text received, echo: "+ text.substring(0, 200));     } }  res.sendstatus(200); }); 

how implement in .net mvc application. how implement line

app.post('/webhook/', function(req, res) 

in controller in mvc.

at last searching , gathering data

facebook post model json data

{ "entry": [{      "messaging":[{         "sender": {           "id": "1126306517444636"         },         "recipient": {           "id": "514501872066958"         },         "timestamp": 1469541638971,         "message": {           "mid": "mid.1469541638961:5d5d5d5bf1194eb824",           "seq": 64,           "text": "hi"         }          }         ]    } ] } 

so have create model

public class sender {    public string id { get; set; } }  public class recipient {     public string id { get; set; } }  public class message {     public string mid { get; set; }     public int seq { get; set; }     public string text { get; set; } }  public class messaging {     public sender sender { get; set; }     public recipient recipient { get; set; }     public long timestamp { get; set; }     public message message { get; set; } }  public class entry {     public list<messaging> messaging { get; set; } }  public class rootobject {      public list<entry> entry { get; set; } } 

and in controller class

public actionresult webhook(rootobject model) {     .................................... } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -