Skip to content

ilbertt/ic_infinitecloud_bot

Repository files navigation

infinitecloud_bot

As Telegram offers unlimited cloud storage, it lacks of the main characteristics of the cloud services: folders structure, file names, etc.

Here comes the Infinite Cloud Bot! This bot simply keeps track of your files in a "filesystem", without saving anything outside of the Telegram chat and so preserving your privacy.

The bot's backend runs in a canister on the Internet Computer.

The previous version of the bot was developed in Node.js and is available at ilbertt/infinitecloud_bot. It was always a pain to keep the bot server running without having to care about the backend, and this is the reason why we have chosen to use the Internet Computer for this new version of the bot.

Usage

Use the bot

Just start a chat with @infinitecloud_bot on Telegram! You'll find more usage instructions at the /help command in the bot chat.

Deploy your own bot

1. Requirements

Make sure you are familiar with the Internet Computer, its concepts and tools.

Make sure you have created a Telegram Bot (instructions) and have obtained a Bot API token from @BotFather (we need this token in the next steps).

Create the following commands for your bot using @BotFather:

  • /help
  • /info
  • /mkdir
  • /explorer
  • /rename_file
  • /move_file

After creating the bot and its commands, create a random alphanumeric string of 256 characters max and add it to the .env file in the root directory under the TELEGRAM_SECRET_TOKEN. You can create the .env file by copying the .env.example file and renaming it to .env. This key will be used to authenticate requests coming from the Telegram servers. We need it in the next steps.

Make sure you have these tools installed:

2. Deploy on the Internet Computer

Make sure you have obtained some cycles to cover the cost of the deployment. See this guide for more info.

# You need to remove the `canister_ids.json` file before deploying (ONLY THE FIRST TIME)
rm canister_ids.json
dfx deploy --ic

A new canister_ids.json file will be created in the root directory when the deployment is completed. You'll find the canister ID for the backend canister in the backend.ic field. We need it in the next step.

If you want to run the canister's bot locally, see the Running the project locally section.

3. Configure Telegram to send messages to the bot via webhooks

Last step is to configure Telegram to invoke the bot via webhooks.

Make an HTTP POST request to the following URL:

curl -X POST https://api.telegram.org/bot<bot-token-from-botfather>/setWebhook?url=https://<backend-canister-id>.raw.icp0.io/&drop_pending_updates=True&secret_token=<TELEGRAM_SECRET_TOKEN>

Running the project locally

If you want to test your project locally, you can use the following commands:

# Starts the replica, running in the background
dfx start

# Deploys your canisters to the replica and generates your candid interface
dfx deploy

In order to send messages to the bot by running the backend locally, you can deploy the canister using the following command:

./scripts/deploy-local-with-ngork-tunnel.sh

Make sure you have ngrok installed.

You still need to configure Telegram to send messages to the bot via webhooks as described in the previous step.

Testing

Unit tests are available with the following command:

./scripts/test.sh

Linting

Linting (with clippy) is available with the following command:

./scripts/lint.sh

Roadmap

  • add support for /delete_file and /delete_dir commands
  • add a Telegram Mini App for the bot

Contributing

Issues and Pull Requests are welcome!