cf-chat-bridge
TypeScript icon, indicating that this package has built-in type declarations

0.14.0 • Public • Published

Chat Bridge by Google Cloud Functions

Latest Stable Version CI codecov

Framework for Google Cloud Functions to bridge communications in chat services, such as

  • LINE -> Slack
  • Slack -> LINE

Example of your index.js

const { Bridge } = require("cf-chat-bridge");

// Your secret variables, see following for more details.
const secrets = require("./your/secrets");
// Your rules to bridge messages, see following for more details.
const rules = require("./your/rules");

// Initialize your bridge.
const bridge = new Bridge({rules, secrets});

// Export your endpoint as a member of module,
// so that Google CloudFunctions can listen /foobar as an endpoint.
exports.foobar = bridge.endpoint();

// Then you can use following endpoints for Slack & LINE webhooks:
//   - Slack: /foobar?source=SLACK
//   - LINE:  /foobar?source=LINE

Example rules

module.exports = [

  /**
   * ONE-WAY bridge: LINE group → SLACK channel(s)
   */
  {
    // From any groups of LINE in which the bot is a member
    source: {
      service: "LINE",
      group: /.*/
    },
    // To "random" channel of Slack in which the bot is a member
    destination: {
      service: "Slack",
      channels: ["random"]
    }
  },

  /**
   * ONE-WAY bridge: Slack channel → LINE group(s)
   */
  {
    source: {
      service: "Slack",
      channel: "dev-test"
    },
    destination: {
      service: "LINE",
      to: ["C3a08fbcbd1c7c3dc4c68d42fb46bd112"],
    },
  },

  /**
   * BOTH-WAY bridge: LINE group ↔ SLACK channel
   */
  {
    pipe: [
      {
        service: "LINE",
        group: "C3a08fbcbd1c7c3dc4c68d42fb46bd112",
      },
      {
        service: "SLACK",
        channel: "general",
      },
    ]
  },
]

Variables you might need

secret.json, like this

{
  "LINE": {
    "CHANNEL_SECRET": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "CHANNEL_ACCESS_TOKEN": "xxxxxxxxxxxxxxxxxxxxxxxx",
  },
  "SLACK": {
    "APP_VERIFICATION_TOKEN": "xxxxxxxxxxxxxxxxxxxxx",
    "APP_OAUTH_ACCESS_TOKEN": "xoxp-xxxxxxxxxxxxxxxxxx"
  }
}

See https://github.com/otiai10/cf-chat-bridge/wiki/Getting-Started for more information about getting started.

How to deploy your index.js to Google Cloud Functions

gcloud functions deploy foobar --trigger-http

See links below for more information

Readme

Keywords

none

Package Sidebar

Install

npm i cf-chat-bridge

Weekly Downloads

2

Version

0.14.0

License

MIT

Unpacked Size

65.7 kB

Total Files

53

Last publish

Collaborators

  • otiai10