This plugin allows you to integrate Telegram functionalities into your Virtuals Game.
npm install @virtuals-protocol/game-telegram-pluginThis plugin allows you to integrate Telegram functionalities into your Virtuals Game.
To install the plugin, use npm or yarn:
``bash`
npm install @virtuals-protocol/game-telegram-plugin
or
`bash`
yarn add @virtuals-protocol/game-telegram-plugin
First, import the TelegramPlugin class from the plugin:
`typescript`
import TelegramPlugin from "@virtuals-protocol/game-telegram-plugin";
Create a worker with the necessary Telegram credentials:
`typescript`
const telegramPlugin = new TelegramPlugin({
credentials: {
botToken: "
},
});
Create an agent and add the worker to it:
`typescript
import { GameAgent } from "@virtuals-protocol/game";
const agent = new GameAgent("
name: "Telegram Bot",
goal: "Auto reply message",
description: "A bot that can post send message and pinned message",
workers: [
telegramPlugin.getWorker(),
],
});
`
Initialize and run the agent:
`typescript
(async () => {
await agent.init();
const agentTgWorker = agent.getWorkerById(telegramPlugin.getWorker().id);
const task = "PROMPT";
await agentTgWorker.runTask(task, {
verbose: true, // Optional: Set to true to log each step
});
})();
`
The TelegramPlugin provides several functions that can be used by the agent:
- sendMessageFunction: Send message.sendMediaFunction
- : Send media.createPollFunction
- : Create poll.pinnedMessageFunction
- : Pinned message.unPinnedMessageFunction
- : Unpinned message.deleteMessageFunction
- : Delete message.
method to listen on:
`typescript
telegramPlugin.onMessage((msg) => {
console.log("Received message:", msg);
});
`
$3
To handle poll answers, use the onPollAnswer method:
`typescript
telegramPlugin.onPollAnswer((pollAnswer) => {
console.log("Received poll answer:", pollAnswer);
});
``This project is licensed under the MIT License.