Recast.AI is now part of SAP.
Recast.AI is now part of SAP.
Slack

Code & Webhooks

If you want to extend Bot Builder with custom code, you can call your API with webhook actions.

Recast.AI - Webhook url

You must provide a full url or route (starting with a '/') to be called by Bot Builder, allowing you to run code or API calls.

If you provide a route, it will be added to your bot's base url (configurable in your bot's settings).

Recast.AI - Bot url settings

Since the current version of webhook does not support authentication headers, your endpoints are open and reachable from anywhere. We have version 2.0 in the works which will let you secure all external endpoints.

What your code will receive

You will receive a POST HTTP request on this route, with all the conversation state.

Then you can perform any calculation, database checks or external API calls and send back data to Bot Builder. The body format is the following:

{
  "conversation": {
    "id": "A_CONVERSATION_ID",
    "language": "en",
    "memory": {
      "person": {
        "fullname": "Francois",
        "raw": "Francois",
        "confidence": 0.95
      }
    },
    "skill_stack": ["get-weather"],
    "skill": "small-talk",
    "skill_occurences": 1
  },
  "nlp": {
    "source": "hi",
    "intents": [
      {
        "slug": "greetings",
        "confidence": 0.99
      }
    ],
    "sentiment": "vpositive",
    "entities": {},
    "act": "assert",
    "type": null,
    "version": "2.10.1",
    "processing_language": "en",
    "language": "en",
    "uuid": "96597974-3ee1-4743-8a5d-341b67effb9a"
    "status": 200,
    "timestamp": "2017-10-25T21:36:02.071243+00:00",
  }
}

How to format your reply?

Send back a formatted message, Bot Builder will forward it to the user. Of course all messages format from Bot Connector are supported.

See more about messages format

Code example

Copy-paste this snippet in a file, install the dependencies, and run the file ;)

JS: npm install express body-parser --save

Python: pip install flask

Ruby: gem install sinatra

PHP: composer require slim/slim

JS
Ruby
Python
PHP
const express = require('express')
const bodyParser = require('body-parser')

const app = express() 
const port = 5000 
app.use(bodyParser.json()) 

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

  res.send({
    replies: [{
      type: 'text',
      content: 'Roger that',
    }], 
    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 5000') 
})

Update the conversation memory

If you send back a new memory, all the previous memory will be replaced.