2

I'm developing SAP Conversational AI bot to handle login to sap and product inquire through single webhook.js file which always hits to /login section , I want to modify this file (presales_assistance_webhook.js) to handle ,multiple post support and cannot use multiple files due to SAP Conversational AI limitation . I'm new to nodejs and need some expert support for this.

//1.login intent: app.post('/login ', (req, res) => {})

//2.product inquiry intent: app.post('/presales', (req, res) => {})

presales_assistance_webhook.js

const express = require('express')
const bodyParser = require('body-parser')

const app = express()
const port = process.env.PORT || 5000
app.use(bodyParser.json())

app.post('/login', (req, res) => {
  console.log(req.body)


  res.send({
    replies: [{
      type: 'text',
      content: 'Welcome to b1 system !',
    }],
    conversation: {
      memory: {
        key: 'value'
      }
    }
  })
})
app.post('/presales', (req, res) => {
  console.log(req.body)


  res.send({
    replies: [{
      type: 'text',
      content: 'Output ok',
    }],
    conversation: {
      memory: {
        key: 'value'
      }
    }
  })
})

app.post('/errors', (req, res) => {
  console.log(req.body)
  res.send()
})

app.listen(port, () => {
  console.log(`Server is running on port ${port}`)
}) 
Sébastien
  • 21
  • 3
Sanjeewa
  • 555
  • 1
  • 9
  • 22

2 Answers2

1

You are doing it well. That code works for me.

const express = require('express')
const bodyParser = require('body-parser')

const app = express()
const port = process.env.PORT || 5000
app.use(bodyParser.json())

app.post('/login',getLoginInformations);
app.post('/presales',getPresalesInformations);

function getLoginInformations(req, res) {  
  console.log(req.body) 
  res.send({
    replies: [{
      type: 'text',
      content: 'Welcome to b1 system !'
    }],
    conversation: {
      memory: {
        key: 'value'
      }
    }
  })
}

function getPresalesInformations(req, res) {  
  console.log(req.body) 
  res.send({
    replies: [{
      type: 'text',
      content: 'Output ok'
    }],
    conversation: {
      memory: {
        key: 'value'
      }
    }
  })
} 
app.post('/errors', (req, res) => {
  console.log(req.body)
  res.send()
})

app.listen(port, () => {
  console.log(`Server is running on port ${port}`)
})

Sanjeewa
  • 555
  • 1
  • 9
  • 22
severino
  • 11
  • 4
0

according to this answer you can simply use

    app.get(
    ['/test', '/alternative', '/barcus*', '/farcus/:farcus/', '/hoop(|la|lapoo|lul)/poo'],
    function ( request, response ) {

    }
);
FarhadMohseni
  • 395
  • 5
  • 8