GithubHelp home page GithubHelp logo

isabella232 / ringcentral-chatbot-core Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ringcentral/ringcentral-chatbot-core

0.0 0.0 0.0 953 KB

This is a fork of https://github.com/ringcentral/ringcentral-chatbot-js, the goal is put bot logic into one standalone module so add-in framework or other project can use it.

License: MIT License

Shell 2.16% JavaScript 0.34% TypeScript 97.49%

ringcentral-chatbot-core's Introduction

RingCentral chatbot framework Core module

This is a fork of https://github.com/ringcentral/ringcentral-chatbot-js, the goal is put bot logic into one standalone module so add-in framework or other project can use it.

How to use

import { extendApp } from 'ringcentral-chatbot-core'
import express from 'express'

function eventHandler ({
    type, // could be 'BotRemoved', 'Message4Bot', 'BotGroupLeft', 'BotJoinGroup', 'Maintain', 'SetupDatabase'
    bot, // the bot instance, check src/models/Bot.ts for instance methods
    text, // the text message user posted in chatgroup
    group, // the group object, can get chat group id from group.id
    userId, // message creator's id
    message // message object, check ringcentral api document for detail
}) {
    console.log(
        type,
        bot,
        text,
        group,
        userId,
        message
    )

  // bot.sendMessage(groupId, body)
  if (type === 'BotJoinGroup') {
    bot.sendAdaptiveCard(group.id, {
      $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
      type: 'AdaptiveCard',
      version: '1.3',
      body: [
        {
          type: 'TextBlock',
          text: 'hello!',
          size: 'large'
        },
        {
          type: 'TextBlock',
          text: 'I am a chat bot',
          weight: 'bolder'
        }
      ]
    })
  } else if (type === 'Message4Bot') {
    bot.sendAdaptiveCard(group.id, {
      $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
      type: 'AdaptiveCard',
      version: '1.3',
      body: [
        {
          type: 'TextBlock',
          text: 'hello!',
          size: 'large'
        },
        {
          type: 'TextBlock',
          text: 'You posted: ' + text,
          weight: 'bolder'
        }
      ]
    })
  }
}

const botConfig = {
    adminRoute: '/admin', // optional
    botRoute: '/bot', // optional
    models: { // optional
        Bot: 'your bot data model defination' // check src/models/Bot.ts as a example, optional
    }
}

let app = express()
const skills = []
app = extendApp(app, skills, eventHandler, botConfig)
app.listen(3000, () => {
    console.log('server running')
})

Exposed routes

Bot instance methods

Check src/models/Bot.ts for details.

More details

Check https://github.com/ringcentral/ringcentral-chatbot-js

demos

License

MIT

ringcentral-chatbot-core's People

Contributors

dakingkong avatar embbnux avatar zxdong262 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.