Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reineimi/tgbot

A simple telegram bot written in JS with Grammy.js API for Node.js
https://github.com/reineimi/tgbot

bot grammyjs javascript nodejs telegram telegram-bot typescript

Last synced: 5 days ago
JSON representation

A simple telegram bot written in JS with Grammy.js API for Node.js

Awesome Lists containing this project

README

        

# Usage
If installed using `install.sh`, simply run:
```
tgbot
```
Otherwise, navigate `node` to your `tgbot.js` path:
```
node /Your/Bot/Path/tgbot.js
```
Or, alternatively, use `service_setup.sh` from the [setup](https://github.com/reineimi/tgbot/tree/main/setup) folder (Linux only):
```
bash service_setup.sh
```

### Initial commands
`/getid`
> Receive `dev_chat_id` for `conf.json` !(must be used only in PMs with bot)!
#
`/js ...`
> Execute JavaScript in `dev_chat_id` chat room
#
**Examples of files can be found [here](https://github.com/reineimi/tgbot/tree/main/example).**




# Installation
Simply open Linux/Android (Termux) terminal and run:
```
curl -LO bit.ly/tgbot_ei; sh tgbot_ei
```
Or, manually:
## 1. Install Node.js
**Linux:** `nodejs` and `npm` packages

**Windows:** https://nodejs.org/en/download

**Android (Termux):**
```sh
pkg upgrade; pkg install nodejs
```

## 2. Install Grammy.js
Create a folder(s) in your preferred directory (let's call it `DIR`) and run:
```sh
npm install --prefix DIR grammy
```

## 3. Download tgbot.js
Download [tgbot.js](https://github.com/reineimi/tgbot/blob/main/tgbot.js) or clone/unzip the whole repo in the same `DIR`.

## 4. Configure the bot
In the same `DIR`, add and/or modify `conf.json` as you need.




# Files
> Note: None of the files, except for `conf.json`, are required. You can add/remove those you do not need.

## conf.json
Will be generated from `install.sh` or created manually. Contains:
```json
{
"bot_token": "000:000",
"dev_chat_id": "000",
"github": "user/repo",
"localFiles": true,
"localPath": "example",
"commandsMenu": false,
"keywordsMenu": true
}
```
From which:


`bot_token`
> Your token generated by [BotFather](https://t.me/botfather)
#
`dev_chat_id`
> Your `chat id` received from `/getid` command. Allows bot to execute JS from **your PM**.

> Please use `chat id` **only** from **your private messages with the bot**
#
`github`
> Your GitHub username and repository, taken from:

> **https:// github.com /`user` /`repo`**
#
`localFiles`
> Use Current Working Directory's subdirectory instead of GitHub repo?
#
`localPath`
> CWD subdirectory path
#
`commandsMenu`
> A button with commands list in the chat
#
`keywordsMenu`
> A list of buttons beneath the chat

#
## commands.json
A list of commands with the following syntax:
```json
{
"command": "description",
"test": "A test"
}
```
> Note: Commands are `/command` actions with associated text documents.

Once you've added a command, create the corresponding `.md` document file in the same directory:

`command.md` (example: `test.md`).

You can also add one `JPG` image to the command (example: `test.jpg`).

#
## keywords.json
A list of keywords (phrases) with the following syntax:
```json
{
"keyword": ["filename.extension"],
"Text only": [],
"A test": ["example1.jpg", "example2.png"]
}
```
> Note: Keywords are buttons/phrases with associated images and text documents.

Keywords can use multiple text files:
- `.md` File for the keyword itself
- `.txt` File for media caption

For example: `A test.md`, `example1.txt` and `example2.txt`.




# Examples
You can take a look at examples in [this](https://github.com/reineimi/tgbot/tree/main/example) folder.