Hosting: Zeabur (Deno)
Zeabur is a platform that allows you to deploy your full-stack applications with ease. It supports various programming languages and frameworks, including Deno and grammY.
This tutorial will guide you how to deploy your grammY bots with Deno to Zeabur.
Looking for the Node.js Version?
This tutorial explains how to deploy a Telegram bot to Zeabur using Deno. If you’re looking for the Node.js version, please check out this tutorial instead.
Prerequisites
To follow along, you need to have Git
Method 1: Create a New Project from Scratch
Make sure you have Deno installed on your local machine.
Initialize your project and install some necessary dependencies:
# Initialize the project.
mkdir grammy-bot
cd grammy-bot
# Create main.ts file
touch main.ts
# Create deno.json file to generate lock file
touch deno.json
2
3
4
5
6
7
8
9
Then modify main
file with the following code:
import { Bot } from "https://deno.land/x/grammy@v1.31.1/mod.ts";
const token = Deno.env.get("TELEGRAM_BOT_TOKEN");
if (!token) throw new Error("TELEGRAM_BOT_TOKEN is unset");
const bot = new Bot(token);
bot.command("start", (ctx) => ctx.reply("Hello from Deno & grammY!"));
bot.on("message", (ctx) => ctx.reply("How can I help you?"));
bot.start();
2
3
4
5
6
7
8
9
10
11
12
Note: Get your bot token with @Bot
Father on Telegram, and set is as an environment variableTELEGRAM
in Zeabur._BOT _TOKEN You can check out this tutorial for setting environment variables in Zeabur.
Then run the following command to start your bot:
deno -IN main.ts
Deno will automatically download the dependencies, generate the lock file, and start your bot.
Method 2: Use Zeabur’s Template
Zeabur has already provided a template for you to use. You can find it here.
You can just use the template and start writing your bot’s code.
Deploying
Method 1: Deploy from GitHub in Zeabur’s Dashboard
- Create a repository on GitHub, it can be public or private and push your code to it.
- Go to Zeabur dashboard.
- Click on the
New Project
button, and click on theDeploy New Service
button, chooseGit
as the source and select your repository.Hub - Go to
Variables
tab to add your environment variables likeTELEGRAM
._BOT _TOKEN - Your service will be deployed automatically.
Method 2: Deploy with Zeabur CLI
cd
into your project directory and run the following command:
npx @zeabur/cli deploy
Follow the instructions to select a region to deploy, and your bot will be deployed automatically.