Skip to main content

Introduction

This guide covers creating and deploying Telegram bots on Shard Cloud.

Creating a Telegram Bot

1

Open BotFather

Open Telegram and search for @BotFather.
2

Create New Bot

Send /newbot and follow the prompts to name your bot.
3

Get Token

BotFather will provide your bot token. Save it securely.
Security: Keep your bot token secret. Anyone with it can control your bot.

Creating Your Bot

Setup

npm init -y
npm install node-telegram-bot-api

Basic Bot Code

index.js
const TelegramBot = require('node-telegram-bot-api');

const token = 'YOUR_BOT_TOKEN';
const bot = new TelegramBot(token, { polling: true });

bot.on('message', (msg) => {
  const chatId = msg.chat.id;
  
  if (msg.text === '/start') {
    bot.sendMessage(chatId, 'Hello! I am your bot.');
  } else if (msg.text === '/ping') {
    bot.sendMessage(chatId, 'Pong!');
  }
});

console.log('Bot is running...');

Package.json

package.json
{
  "name": "telegram-bot",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "node-telegram-bot-api": "^0.64.0"
  }
}

Shard Cloud Configuration

.shardcloud
DISPLAY_NAME=Telegram Bot
DESCRIPTION=My Telegram Bot
MAIN=index.js
MEMORY=256
VERSION=recommended

Deploying

1

Prepare Your Files

Ensure you have:
  • Your bot code file
  • package.json (Node.js) or requirements.txt (Python)
  • .shardcloud
2

Exclude Unnecessary Files

Remove: node_modules/, __pycache__/, venv/
3

Create ZIP Archive

Compress your project folder.
4

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload.

Testing

After deployment, open Telegram, find your bot, and send /ping. It should reply with “Pong!”.

Additional Resources

Troubleshooting

  • Verify your bot token is correct
  • Check that polling is enabled
  • Review logs in the dashboard
Only one instance of your bot can use polling at a time. Stop other instances.