recastai-botconnector

1.0.1 • Public • Published

SDK-NodeJS-bot-connector

alt text

Recast.AI official SDK in Node.js for bot connector

Synospis

This module is a wrapper around the Bot connector API, and allows you to connect your bot to any channels

Installation

npm install --save recastai-botconnector

Usage

Catch and reply

const Bot = require('recastai-botconnector')
const express = require('express')
const bodyParser = require('body-parser')
 
/* server setup */
const app = express()
 
app.set('port', 5000)
app.use(bodyParser.json())
app.post('/', (req, res) => myBot.listen(req, res))
app.listen(app.get('port'), () => console.log('Bot running on port', app.get('port')))
 
/* setup bot */
const myBot = new Bot({ botId: 'YOUR BOT ID', userSlug: 'YOUR USER SLUG', userToken: 'YOUR USER TOKEN' })
 
/* on new message */
myBot.onTextMessage(message => {
  console.log(message)
  const text = {
    type: 'text',
    content: 'Here is a reply!',
  }
 
  message.reply(text)
  .then(() => console.log('Message successfully sent'))
  .catch(err => console.log(`Error while sending message: ${err}`))
})

Push a message to one participant

const payload = {
  type: 'text',
  content: 'Here is your pushed message',
}
 
myBot.sendMessage(payload, conversationId, recipient)
.then(() => console.log('Message successfully sent'))
.catch(err => console.log(`Error while sending message: ${err}`))

Broadcast a message to all participants

const payload = {
  type: 'text',
  content: 'Here is a broadcast message',
}
 
myBot.broadcast(payload)
.then((res) => {
  console.log(res)
})

Documentation

You can find the full documentation here.

Specs

This module contains 2 classes, as follows:

  • Bot is the client allowing you to catch messages sent to your bot
  • Message is the class used for replies.

More

You can view the whole API reference at man.recast.ai.

Author

Bruno Gantelmi, bruno.gantelmi@recast.ai

You can follow us on Twitter at @recastai for updates and releases.

License

Copyright (c) [2016] Recast.AI

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i recastai-botconnector

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • recastai