跳到主要内容

Deploy in Gitter

Gitter is an open-source instant messaging and chat room system for developers and users of GitLab and GitHub repositories. In this how-to guide, you will learn how to deploy the ding-dong bot in Gitter locally from the Wechaty gitter template.

Deploy in Gitter

Requirements

  1. Your system must have Node.js installed (version >= 12).
  2. Your system must have Wechaty (version >= 0.40).

Deployment

Run wechaty-puppet-gitter:

npm install wechaty-puppet-gitter
export WECHATY_PUPPET=wechaty-puppet-gitter
npm start

Integration

Let's take up an example on how to integrate the ding-dong bot from Wechaty gitter template. The step is similar for all other bots as well.

Prerequisite

  1. Official Wechaty package: package/wechaty.
  2. A TOKEN from gitter so that it can connect to the gitter.im service: developer.gitter.im/docs/services.

You can follow up the steps mentioned below:

  1. Git clone the Wechaty gitter template.
  1. From the root directory install the necessary dependencies using the following commands:
npm install wechaty
npm install wechaty-puppet-gitter
  1. To pass the token, add the snippets below to the head of examples/ding-dong-bot.ts file:
import { Wechaty } from 'wechaty'
/**
* Personal Access Token: this token can be used to access the Gitter API.
* https://developer.gitter.im/apps
*/
const puppet = new PuppetGitter({ token: 'your_gitter_token' })
const wechaty = new Wechaty({ puppet })

wechaty.start()

All necessary functions like onLogout, onLogin, onError, and onMessage are predefined.

  1. Replace your_gitter_token with your 40 digits hexadecimal token id.To generate your own token id, navigate to developer.gitter.im/docs/services and login/signin your account.

  2. Now you can run the bot using the following commands:

WECHATY_LOG=verbose
export WECHATY_PUPPET=wechaty-puppet-gitter
npm start

You have successfully deployed the ding-dong with Gitter!

You can deploy the bot with popular container solutions as well such as:

References

Blogs