1

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?

1 Answer 1

1

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...')
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.