npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ringcentral-chatbot-core

v1.6.0

Published

## Status: work in progress

Downloads

78

Readme

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', 'Message4Others', '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
    isPrivateChat, // if it is a private chat
    message, // message object, check ringcentral api document for detail
    commandLineOptions, // only if set commandLineConfigs in botConfig, would get parse result from text, check doc/command-line-parser.md for detail
}) {
    console.log(
        type,
        bot,
        text,
        group,
        userId,
        message
    )

  // bot.sendMessage(groupId, body)
  if (type === 'BotJoinGroup') {
    await 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'
        }
      ]
    })
    // or send text message
    // await bot.sendMessage(group.id, {
    //   text: 'welcome'
    // })
  } else if (type === 'Message4Bot') {
    await 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'
        }
      ]
    })
    // or send text message
    // await bot.sendMessage(group.id, {
    //   text: 'hi'
    // })
  }
}

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
    },
    commandLineConfigs: [ // optional
      {
        command: 'add'
        options: [
          ['-f, --float <number>', 'float argument'],
          ['-i, --integer <number>', 'integer argument'],
          ['-v, --verbose', 'verbosity that can be increased']
        ]
      }
    ]
    // if set commandLineConfigs in botConfig, would get parsed commandLineOptions object from text, check doc/command-line-parser.md for detail(use commander module)
}

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

Exposed routes

bot

  • /{botConfig.botRoute}/oauth: bot oauth url
  • /{botConfig.botRoute}/webhook: bot webhook url

for administrator

  • /{botConfig.adminRoute}/setup-database: Init data base
  • /{botConfig.botRoute}/update-token: fix token for single bot
  • /{botConfig.botRoute}/maintain: remove dead bots from database, ensure live bots have WebHooks(fix broken subscribe), destroy very old cache data
  • /{botConfig.botRoute}/dump-database: provide administrator with database data for troubleshooting
  • /{botConfig.botRoute}/list-subscriptions: provide administrator with subscriptions data for troubleshooting

Bot instance methods

Check src/models/Bot.ts for details.

Params controlled by ENV

 // default is true, can be set to false
process.env.DYNAMO_SAVE_UN_KNOWN=true

// default is false, can be set to true
process.env.DYNAMO_SAVE_JSON_AS_OBJECT=false

// default is false, can be set to true
process.env.USE_HEROKU_POSTGRES = false

// set db url
RINGCENTRAL_CHATBOT_DATABASE_CONNECTION_URI = 'sqlite:///file/db.sql'

// when set to 'dynamo', process.env.RINGCENTRAL_CHATBOT_DATABASE_CONNECTION_URI will be ignored
process.env.DIALECT = 'dynamo'

More details

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

demos

License

MIT