Marcin Bębenek
Marcin Bębenek

Reputation: 11

How to capture WhatsAapp message in my app from Twilio Sandbox

I want to build chat conversation from my app to WhatsApp. I have managed to send and receive between Twilio and my WhatsApp number, All using https://www.twilio.com/console/sms/whatsapp/sandbox. I connected the Sandbox to my App, I'm receiving calls to my webhook but the content of that post is empty. How I could capture message content in my app?

Upvotes: 1

Views: 189

Answers (1)

Guillermo Peña
Guillermo Peña

Reputation: 11

Include this in your code:

app.use(BodyParser.urlencoded({ extended: true }))

Full example:

const BodyParser = require('body-parser')
const Express = require('express')
const Http = require('http')

// App
let app = Express()
app.use(BodyParser.urlencoded({ extended: true }))

// Router
var router = Express.Router()
router.post('/', function(req, res) {
   console.log('\nREQUEST RECEIVED!!')
   console.log(req.body)
   res.writeHead(200, {'Content-Type': 'text/xml' })
   res.end()
})
app.use(router)

// Server
let server = Http.createServer(app)
server.listen( 3115, err => {
  if (err) console.log( 'Error listening : ' + err )
  else     console.log('Listening...')
})

Upvotes: 1

Related Questions