🧠
GAME by Virtuals
Get API KeyGAME SDK
  • Introducing GAME
  • GAME Overview
    • Transcript of GAME Knowledge Session
  • Release Note
  • GAME Cloud
  • GAME SDK
  • How to
    • Articles
      • Prompt Design Playbook for Agent Configuration via GAME
      • Simulate Reaction & Output in GAME Cloud
      • GAME Cloud Custom Functions: Retrieving Articles Using Dev.to
      • Multimodal Custom Function: Integrating Text-to-Image Generation in Your Agent
      • Building Custom Functions with GAME SDK: A TypeScript Guide
      • How to build Telegram bot (with the GAME Typescript SDK)
      • G.A.M.E Cloud or G.A.M.E SDK? Decoding the Right Choice for Your Project
      • GAME Cloud - How to Define Reply Worker and Worker Prompts
      • Dataset Upload for AI Agents in GAME Cloud: Guidelines, Common Issues, and Best Practices
    • Video Tutorials
  • Commonly Asked Questions
    • My Agent is not tweeting
  • GAME Use Cases
Powered by GitBook
On this page
  • 1. Register a new telegram bot with telegram
  • 2. Git clone repo
  • 3. Run the program
  • 4. Let's talk to your agent!
  • Congratulations, you've just built your first telegram bot with the GAME SDK!
  • Stay Connected and Join the Virtuals Community! 🤖 🎈
  1. How to
  2. Articles

How to build Telegram bot (with the GAME Typescript SDK)

PreviousBuilding Custom Functions with GAME SDK: A TypeScript GuideNextG.A.M.E Cloud or G.A.M.E SDK? Decoding the Right Choice for Your Project

Last updated 2 months ago

Hello! Today we're going to guide you how to build a telegram bot using an easy-to-use plugin from the GAME SDK. You'll be chatting with your telegram bot by the end of the tutorial!

1. Register a new telegram bot with telegram

First, we're going to register a new telegram bot. Go to your Telegram account and DM @BotFather

In the chat with the BotFather, click /start and click /newbot! It will guide you through creating a new bot. First, give your bot a name (it doesn't have to be unique and you can change this anytime.) Then, BotFather will ask you to give the bot a unique username. The username must end in "bot." And the username cannot be changed. A bot's username can look like this: - my_agent_bot - myAgentBot - myAgent_Bot or any combination of the above!

Once you've set the name and username of your bot, the BotFather will give you an API key. Save it, we will use it in our project :)

By the way, while we are here, you can also edit your bot anytime! Click or type in /mybots and you'll get to a menu where you can edit your bot's name anytime and set your bot's image and description. You do not have to do any of this right now to complete this tutorial.

2. Git clone repo

Now, let's go to our dev environment and git clone the game-node repository.

// clone the repository
git clone https://github.com/game-by-virtuals/game-node

// go to the plugin directory
cd game-node/plugins 

Now, we are in the plugins folder. There are a few awesome ones here that you can play with right away - such as the discordPlugin, twitterPlugin and the onChainActionsPlugin (where you can handle crypto wallets and do on-chain transactions.) But for today, we will just focus on the telegramPlugin.

Let's go into the telegramPlugin folder and install the dependencies.

// go into the telegram plugin folder
cd telegramPlugin

// install dependencies
npm install

We are going to run the example code that comes in the telegramPlugin. Open src/example.ts. Replace <BOT_TOKEN> with the Telegram API key that we generated from the BotFather.

In the example.js file

The example file actually contains three agents. There is an autoReply agent, a financial agent, and a nutritionist agent. When we run this program, all three agents will run at the same time and they will all try to respond to you!

When you are modifying this program, you can delete all but one agent. You can customize your agent by changing the name, goal, and description!

3. Run the program

Great! Now that you've entered your GAME API key and the bot token, we are ready to run the code.

At this point, you can edit the agents in the example.ts file. The example comes with three agents (a generic autoReply agent, a financial agent, and a nutrionist agent) you can par the code down to just one agent. Give your agent some personality and specialty by editing the name, goal, and description.

Let's compile the typescript. Edit the package.json so that the script for "tsup" will compile example.ts instead of index.ts. Save the changes.

In the terminal, run the following commands:

// install dependencies
npm install

// this command compiles the example.ts
// and places it in a new "dist" folder
npm run tsup

// run the compiled example.js
node dist/example.js

You should start seeing a running log of activity in the terminal.

4. Let's talk to your agent!

Go back to telegram and send a message to your bot. If you are able to see some responses from your Telegram bot, it means that your bot is working!

Stay Connected and Join the Virtuals Community! 🤖 🎈

At the moment of this tutorial, we recommend you to be on node version 23 and npm version 10.9.2. We recommend the .

Replace <API_TOKEN> with your GAME API key. If you do not have one, you can generate one here:

Congratulations, you've just built your first telegram bot with the GAME SDK!

🎉
node version manager, NVM
https://console.game.virtuals.io/
GitHub - game-by-virtuals/game-nodeGitHub
The GAME node repository
Logo
Cover

X: @GAME_Virtuals

https://x.com/GAME_Virtuals

For updates and to join our live streaming jam sessions every Wednesday. Stay in the loop and engage with us in real time!

Cover

Discord: @Virtuals Protocol

http://discord.gg/virtualsio

Join Discord for tech support and troubleshooting, and don’t miss our GAME Jam session every Wednesday!

Cover

Telegram: @Virtuals Protocol

https://t.me/virtuals

Join our Telegram group for non-tech support! Whether you need advice, a chat, or just a friendly space, we’re here to help!

The famous bot father of telegram! Where all TG bots are born
Click or type in /newbot to start
My bot's generated API key
Go to /mybots to edit your bot anytime
Here is where you can set your bot's profile! Give it an image and description
The game-node plugin folder
The example.ts file with the API key and the bot token
your package.json should look like this
What the terminal logs should look like as your bot is receiving messages and responding