Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jliuhtonen/mvb
Small library for implementing Telegram bots
https://github.com/jliuhtonen/mvb
Last synced: 3 months ago
JSON representation
Small library for implementing Telegram bots
- Host: GitHub
- URL: https://github.com/jliuhtonen/mvb
- Owner: jliuhtonen
- Created: 2015-07-22T15:04:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T18:13:35.000Z (over 1 year ago)
- Last Synced: 2024-04-15T00:13:34.466Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 324 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minimum Viable Bot
Small library for implementing Telegram bots
## Usage
Register a bot and obtain an authentication token with Telegram, see [introduction to bots](https://core.telegram.org/bots).
Create a Mvb instance with your token:
```javascript
import Mvb from 'mvb'const helloBot = new Mvb("myAuthToken")
```Create a command handler with `onCommand`:
```javascript
const unsubscribeFn = helloBot.onCommand('hello', (args, replyFn) => {
const [name] = args
replyFn(`Hello, ${name}!`)
}
````onCommand` takes two parameters. The command name without leading slash and an "event handler" function that will be called when the command is invoked. The event handler gets two parameters as well:
* _args_: an array of arguments passed to the command
* _replyFn_: a function that takes a string that you can use to send a reply messageIt will return a function that you can use to unsubscribe from the command events.
Registering a command handler with `onCommand` returns a function that you can use to unsubscribe from the commands of this type.
So now, saying `/hello Telegram` in a group chat that the bot is a member of (or in a private conversation) will result in the bot responding `Hello, Telegram!`.
## Development
### Setting up
Install Babel
```npm install -g babel```Install dependencies
```npm install```### Compiling
```npm run compile```