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

Hello world

Each time a message is posted on one of the channels your bot is connected to, it receives a POST request on the endpoint you've set on the platform. To reply, you need to make a post request with your bot's Request Token available in your bot settings. In this example, we use SDKs to make it simpler. :)

Receive messages and send "Hello world"

1. Copy-paste this snippet in a file.

2. Replace the REQUEST_TOKEN by your token.

3. Install the dependencies and run the file

JS: npm install recastai express body-parser

Python: pip install recastai flask

Ruby: gem install RecastAI sinatra

PHP: composer require recastai/sdk-php

var express = require('express')
var bodyParser = require('body-parser')
var recastai = require('recastai').default

var connect = new recastai.connect('YOUR_REQUEST_TOKEN')

var app = express()

/* Server setup */
app.set('port', 5000)
app.use(bodyParser.json())'/', function(req, res) {
  connect.handleMessage(req, res, onMessage)

function onMessage (message) {
  // Get the content of the message
  var content = message.content

  // Get the type of the message (text, picture,...)
  var type = message.type

  // Add a reply, and send it
  message.addReply([{ type: 'text', content: 'Hello, world' }])

app.listen(app.get('port'), function () { console.log('App is listening on port ' + app.get('port')) })

4. Download ngrok and launch it ngrok http 5000

5. Go to your bot page, in the Bot Connector tab. In the field Current bot webhook, paste the https URL you got from ngrok

6. Send a message throught the channel you have previsouly created!

Next steps