Giter VIP home page Giter VIP logo

botpress-broadcast-latest-version's Introduction

@botpress/broadcast

X: Migrated. Requires documentation update.

Get started

botpress install broadcast

The broadcast module should now be available in your bot UI, and the APIs exposed.

Features

Send according to Users timezone

You can decide wether the scheduled time is abolute to the bot's time or to individual users. If no timezone information available for the user, GMT is chosen.

Send as Javascript snippet

Instead of sending text, you can decide the behavior of the sending function and do basically anything. The function will be called for every message (so for every user).

Variables exposed:

  • bp botpress instance
  • userId the userId to send the message to
  • platform the platform on which the user is on

The built-in Facebook Messenger snippets are example of Javascript execution (see UI).

Filtering

You can apply filters to the broadcasts. Filters are small javascript functions that will be evaluated before sending the broadcast to a user. The condition is called for every users the broadcast is scheduled to.

Variables exposed to the filter function:

  • bp botpress instance
  • userId the userId to send the message to
  • platform the platform on which the user is on

The function needs to return a boolean or a Promise of a boolean.

Note: Starting your function with return is optional.

Examples

Send a message only to users on Facebook
["platform === 'facebook'"]
Send a message only to subscribed users

Note: Assuming your bot has a subscriptions table that holds userId and platform

// in your bot's index.js

bp.isUserSubscribed = (userId, platform) => {
  return bp.db.get()
  .then(knex => 
    knex('subscriptions')
    .where({ userId, platform })
    .select('count(*) as count')
    then().get(0).then(({count}) => count > 0)
  )
}
["bp.isUserSubscribed(userId)"]

Roadmap

  • User segmentation

API

GET /api/botpress-broadcast/broadcasts

Returns a list of the scheduled broadcasts.

PUT /api/botpress-broadcast/broadcasts

Schedules a new broadcast.

Body

{
  date: string, // *required*, 'YYYY-MM-DD'
  time: string, // *required*, 'HH:mm'
  timezone: null|int, // null (users timezone), or integer (absolute timezone)
  type: string, // *required*, 'text' or 'javascript'
  content: string // *required*, the text to be sent or the javascript code to execute,
  filters: [string] // filtering conditions, Javascript code
}

Response

"Hello, Human!"

POST /api/botpress-broadcast/broadcasts

Update an existing broadcast. Same as PUT except that id is also necessary. You can't modify a processing broadcast.

DELETE /api/botpress-broadcast/broadcasts/:id

Delete an existing broadcast. You can't delete a processing broadcast.

Community

Pull requests are welcomed! We believe that it takes all of us to create something big and impactful. There's a Slack community where you are welcome to join us, ask any question and even help others.

Get an invite and join us now! ๐Ÿ‘‰https://slack.botpress.io

License

botpress-broadcast is licensed under AGPL-3.0

botpress-broadcast-latest-version's People

Contributors

to7be avatar

Watchers

 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.