Jack is a Telegram Bot developed using Typescript. His purpose is to provide an enviroment to store messages (announcements, reminders, etc) and broadcast them among registered groups.
Jack is made with Typescript
, so Node.js
is used to deal with initialization and dependencies. The version of node used is v14.16.1
with npm version v6.14.12
.
Project dependencies can be installed with command:
npm install
The configuration of the bot is made by environment variables, with can be manually inserted (in case of Linux with export
command) or using a .env
file. The variables required are the following:
-
BOT_TOKEN: The Token generated by the
Telegram Bot Father
-
DATABASE_URL: The URL used to connect to the database (required by prisma)
-
PORT: The port in which the server will be listening
The initialization may be performed in two different ways, either by compiling the Typescript code (which by tsconfig.json outDir will be compiled to dist
folder) with the following command:
npx tsc
node dist/index.js
Or it can be done with the dependency ts-node-dev
that starts a server to monitor the project files, restarting the application with any changes applied and saved to files. The dependency can be used in the following command:
npx ts-node-dev src/index.ts
Prisma is used to manage the Relational Database (postgresql used), dealing with migrations and basic operations (querys, insertions, etc). So the prisma CLI (Command Line Interface) is recommended in order to call prisma commands.
To start a table in the database provided (contained on the DATABASE_URL environt variable) a migration is necessary. The following commands provides the migration execution.
- Development
npx prisma migrate dev --name NAME_OF_MIGRATION
- Production and Testing Environments
npx prisma migrate deploy
After performing the previous steps, talking to the bot through commands allows to use the bot accordingly to the desired purpose. The main steps are registering chats and adding messages for posting.
Currently there are five available commands as described below:
-
comandos: List all available commands of the bot
-
register: Registers a group chat id for redistribution of messages (called on group)
-
add: Starts the add wizard to add a message. The steps are the following:
-
Send the Message or forward a Message to be stored
-
Inform the period which the message will be distributed. Accepted formats:
- number ( in minutes ) | e.g. 10
- number + m | e.g. 15m
- number + h | e.g. 1h
- number + h + number ( in minutes ) | e.g. 1h20
- number + h + number + m | e.g. 2h30m
-
Preview displayed asking to confirm the message or restart the process
-
Confirmation of message registration
-
-
del: Deletes a single message. Available messages are displayed on keyboard.
-
update: Updtates a single message. Available messages are displayed on keyboard.
-
clear: Clear all messages stored
- Support to Language Selection (currently only supports PT-BR)
- Removal of messages given Date argument
Update of specific messageSelection of Groups for distribution