2

我正在开发 SAP Conversational AI 机器人来处理登录到 sap 和通过单个 webhook.js 文件查询产品,该文件总是命中 /login 部分,我想修改这个文件(presales_assistance_webhook.js)来处理多个帖子支持并且不能使用由于 SAP Conversational AI 限制,多个文件。我是 nodejs 的新手,需要一些专家支持。

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

//2.产品查询意图: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}`)
}) 
4

2 回答 2

1

你做得很好。该代码对我有用。

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}`)
})

于 2019-05-04T15:11:22.793 回答
0

根据这个答案,您可以简单地使用

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

    }
);
于 2020-08-09T00:44:30.113 回答