Torihiki (とりひき), a Telegram and Discord-Self bot, that forwards Discord messages to Telegram.
To get started with the Torihiki, follow these steps:
-
Clone the repository:
git clone https://github.com/leovander/torihiki.git cd torihiki
-
Install the necessary dependencies using
pnpm
:pnpm install
-
Set up your environment variables. Create a
.env
file in the root directory based on the.env.example
file:cp .env.example .env
Fill in the required values in the
.env
file:REDIS_PORT="host" DISCORD_TOKEN="personal-token" TELEGRAM_TOKEN="telegram-token-from-botfather" TELEGRAM_CHAT_ID="supergroup-id" TELEGRAM_THREAD_IDS="topicname:messagethreadid;topicname1:messagethreadid1;" TELEGRAM_ADMIN_IDS="userid:userid2:userid3"
See more details on how to get tokens and ids, and set other options: Environment Variables
-
Build the bot:
pnpm build # If working on the project, to watch for changes and run from ./dist pnpm watch
-
Start the bot:
pnpm start
Once the bot is running, admins can interact with it on Telegram using the following command:
/admin queues
- Get queue stats
LOG_LEVEL (default: info)
: Available log levels from winstonjs (https://github.com/winstonjs/winston?tab=readme-ov-file#logging-levels)
REDIS_HOST (default: 127.0.0.1)
: Hostname of redis instanceREDIS_PORT (default: 6379)
: redis instance listening portREDIS_DEFAULT_DB (default: 0)
: Default redis database to use i.e.d0
. (redis's default databdase isd0
when not specified)REDIS_QUEUE_DB (default: 1)
: redis database used by BullMQREDIS_TELEGRAM_SESSION_DB (default: 0)
: redis database used by @telegraf/session
-
TELEGRAM_TOKEN
: Telegram Bot Token (https://core.telegram.org/bots/tutorial#obtain-your-bot-token) -
TELEGRAM_CHAT_ID
: Telegram Group Id- Once you launch your bot, temporarily add the following to the src/lib/telegraf.ts and store the returned id here:
bot.on(message('text'), (ctx) => { console.log(`TELEGRAM_CHAT_ID: ${ctx.chat.id}`); });
-
TELEGRAM_THREAD_IDS
: Delimited Telegram Topic Names & Message Thread Ids e.g.topic-name1:topic-message-thread-id1;topic-name2:topic-message-thread-id2;
- Once you launch your bot, temporarily add the following to the src/lib/telegraf.ts and store the topic name and returned id here:
bot.on(message('text'), (ctx) => { console.log(`TELEGRAM_MESSAGE_THREAD_ID: ${ctx.message.message_thread_id}`); });
-
TELEGRAM_ADMIN_IDS
: WhenTELEGRAM_CHAT_ID
is set on launch, you can get the list of admin user ids e.g.user-id1:user-id2
via redis:get 'telegram:details:admins'
⚠️ Disclaimer: It is against Discord's TOS to use the discord.js-selfbot package this project depends on. Use this at your own risk.
DISCORD_TOKEN
: Your Discord User Token (https://discordjs-self-v13.netlify.app/#/docs/docs/main/general/welcome)
Read more about BullMQ's; Auto-removal of jobs and Retrying failing jobs.
REMOVE_ON_COMPLETE_AGE (default: 3600)
: Maximum age in seconds for job to be kept.REMOVE_ON_COMPLETE_COUNT (default: 1000)
: Maximum count of jobs to be kept.REMOVE_ON_FAIL_COUNT (default: 5000)
: Specifies the maximum amount of jobs to keepATTEMPTS (default: 3)
: The total number of attempts to try the job until it completes.BACKOFF_TYPE (default: exponential)
: Name of the backoff strategy.BACKOFF_DELAY (default: 1000)
: Delay in milliseconds.
Read more about BullMQ's Rate Limiting strategies.
QUEUE_LIMIT_MAX (default: 10)
: Max number of jobs to process in the time period specified induration
.QUEUE_LIMIT_DURATION (default: 60000)
: Time in milliseconds. During this time, a maximum ofmax
jobs will be processed.
- Telegraf Sessions to keep persistent context of user messsages
- BullMQ to manage queue of messages to avoid Telegram Bot Rate Limits
- redis with persistence enabled to; power queues, store sessions and light app details
Contributions are welcome! Here's how you can contribute to this project:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature-name
- Make your changes and commit them:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/your-feature-name
- Create a new Pull Request.
This project is licensed under AGPL-3.0-only.
If you have any questions or suggestions, feel free to open an issue.