Git Product home page Git Product logo

bot-notifications's Introduction

Bot-Notifications

A common request from companies and organizations considering bots is the ability to be able to notify users on news (e.g. new available features).

This project implements a framework called notifications which enables bot authors to implement a notifications capability, with minimal changes to the actual bot.

It also includes a very simple implementation that illustrates the core concepts with minimal configuration.

This project is written in TypeScript.

Source Code

See example folder for a full bot example.

This project was developed on top of the Handoff project.

Preview

Administrator queueing a message: Preview

User receives the message on login: Preview

Basic Usage

// Imports
const express = require('express');
const builder = require('botbuilder');
const notifications = require('botbuilder-notifications');

// Setup Express Server (N.B: If you are already using restify for your bot, you will need replace it with an express server)
const app = express();
app.listen(process.env.port || process.env.PORT || 3978, '::', () => {
    console.log('Server Up');
});

// Replace this functions with custom login/verification for agents
const isAgent = (session) => session.message.user.name.startsWith("Admin");

/**
    bot: builder.UniversalBot
    app: express ( e.g. const app = express(); )
    isAgent: function to determine when agent is talking to the bot
    options: { }
        - mongodbProvider and directlineSecret are required (both can be left out of setup options if provided in environment variables.)
**/
notifications.setup(bot, app, isAgent, {
    mongodbProvider: process.env.MONGODB_PROVIDER,
    directlineSecret: process.env.MICROSOFT_DIRECTLINE_SECRET
});

If you want the sample /webchat endpoint to work (endpoint for the example admin), you will need to include this public folder in the root directory of your project, or replace with your own.

This sample

This sample includes:

  • A rudimentary echo bot
  • A simple WebChat-based front end for use by both Customers and Admins
  • rudimentary admin recognition via the userid entered by users
  • middleware which allows Customers and Admins to enter commands through WebChat that are interpreted and turned into Notifier method calls

How to use this code

  1. Install the npm module
  2. Setup your bot as shown in the 'basic usage' part above

How to build and run this sample project

  1. Clone this repo
  2. If you haven't already, Register your bot with the Bot Framework. Copy the App ID and App Password.
  3. If you haven't already, add a Direct Line (not WebChat) channel and copy one of the secret keys (not the same as the app id/secret)
  4. npm install
  5. npm run build (or npm run watch if you wish to compiled on changes to the code)

Run in the cloud

  1. Deploy your bot to the cloud
  2. Aim your bot registration at your bot's endpoint (probably https://your_domain/api/messages)
  3. Aim at least two browser instances at https://your_domain/webchat?s=direct_line_secret_key

... or run locally

  1. Create an ngrok public endpoint see here for details

  2. Update your bot registration to reference that endpoint (probably https://something.ngrok.io/api/messages) Reference bot to ngrok endpoint

  3. Run your bot on Mac (remember to restart if you change your code):
    Set your environment variables and run your code:
    appId=app_id appPassword=app_password node dist/app.js

  4. Run your bot on Windows with PowerShell (remember to restart if you change your code):
    Set your environment variables
    $env:appId = "app_id"
    $env:appPassword = "app_password"
    Run your code:
    node .\dist\app.js or npm run start

  5. Aim at least two browser instances at http://localhost:3978/webchat?s=direct_line_secret_key

Set up your customer(s) & admins(s), and go

  1. Make one or more instances an agent by giving it a user id starting with the word Admin
  2. Make one or more instances a customer by giving it a user id not starting with the word Admin
  3. The customer bot is a simple echo bot.
  4. As an admin, type you have two options, either write queue MSG to schedule MSG to be presented whenever a new chat is started, or broadcast MSG to force push this message into the current active chat

Good luck!

Required environment variables:

"appId" : "",
"appPassword" : "",
"MICROSOFT_DIRECTLINE_SECRET" : "",
"MONGODB_PROVIDER" : ""      

License

MIT License

bot-notifications's People

Contributors

eladiw 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.