NekoBot supports Telegram platform through Telegram Bot API.
/newbot commandEdit data/platforms_sources.json:
{
"telegram": {
"type": "telegram",
"enable": true,
"id": "telegram",
"token": "your-bot-token-here",
"command_prefix": "/"
}
}Telegram supports both Webhook and long polling modes:
async def set_webhook(self, webhook_url):
await self.platform_server.call_platform_api(
platform_id="telegram",
action="set_webhook",
params={"url": webhook_url}
)No additional configuration needed, NekoBot automatically uses long polling to fetch messages.
| Event Type | Description |
|---|---|
| Message | Text, image, video, and other messages |
| Callback Query | Callback button click |
| Inline Query | Inline search |
| Member Join | Member joins group |
| Member Leave | Member leaves group |
Telegram messages support Markdown and HTML formats:
message = """
*Bold text*
_Italic text_
`Code`
```Code block```
[Link](https://example.com)
"""message = """
<b>Bold text</b>
<i>Italic text</i>
<code>Code</code>
<pre>Code block</pre>
<a href="https://example.com">Link</a>
"""await self.send_group_message(
group_id=chat_id,
user_id=user_id,
message="Hello!",
platform_id="telegram"
)async def send_photo(self, chat_id, photo_url, caption=""):
await self.platform_server.call_platform_api(
platform_id="telegram",
action="send_photo",
params={
"chat_id": chat_id,
"photo": photo_url,
"caption": caption
}
)async def send_video(self, chat_id, video_url, caption=""):
await self.platform_server.call_platform_api(
platform_id="telegram",
action="send_video",
params={
"chat_id": chat_id,
"video": video_url,
"caption": caption
}
)async def send_document(self, chat_id, file_path, caption=""):
await self.platform_server.call_platform_api(
platform_id="telegram",
action="send_document",
params={
"chat_id": chat_id,
"document": file_path,
"caption": caption
}
)async def send_inline_keyboard(self, chat_id):
keyboard = {
"inline_keyboard": [
[
{"text": "Button1", "callback_data": "btn1"},
{"text": "Button2", "callback_data": "btn2"}
],
[
{"text": "Link", "url": "https://example.com"}
]
]
}
await self.platform_server.call_platform_api(
platform_id="telegram",
action="send_message",
params={
"chat_id": chat_id,
"text": "Please select:",
"reply_markup": keyboard
}
)async def send_reply_keyboard(self, chat_id):
keyboard = {
"keyboard": [
[{"text": "Option1"}, {"text": "Option2"}],
[{"text": "Cancel"}]
],
"resize_keyboard": True,
"one_time_keyboard": False
}
await self.platform_server.call_platform_api(
platform_id="telegram",
action="send_message",
params={
"chat_id": chat_id,
"text": "Please select:",
"reply_markup": keyboard
}
)async def on_message(self, message):
if message.get("callback_query"):
callback = message["callback_query"]
callback_id = callback["id"]
data = callback.get("data")
await self.answer_callback_query(callback_id, text="Clicked")
if data == "btn1":
await self.send_group_message(
group_id=callback["message"]["chat"]["id"],
user_id=callback["from"]["id"],
message="You clicked Button1",
platform_id="telegram"
)
async def answer_callback_query(self, callback_id, text=""):
await self.platform_server.call_platform_api(
platform_id="telegram",
action="answer_callback_query",
params={"callback_query_id": callback_id, "text": text}
)async def get_user_profile(self, user_id):
result = await self.platform_server.call_platform_api(
platform_id="telegram",
action="get_chat",
params={"chat_id": user_id}
)
return result.get("data")async def get_group_info(self, group_id):
result = await self.platform_server.call_platform_api(
platform_id="telegram",
action="get_chat",
params={"chat_id": group_id}
)
return result.get("data")async def set_bot_commands(self):
commands = [
{"command": "start", "description": "Start using"},
{"command": "help", "description": "Help"},
{"command": "settings", "description": "Settings"}
]
await self.platform_server.call_platform_api(
platform_id="telegram",
action="set_my_commands",
params={"commands": commands}
)async def get_group_members(self, group_id):
result = await self.platform_server.call_platform_api(
platform_id="telegram",
action="get_chat_member_count",
params={"chat_id": group_id}
)
return result.get("data", {})Telegram API has the following file size limits:
| File Type | Size Limit |
|---|---|
| Photo | 10 MB |
| Video | 50 MB |
| Document | 50 MB (Premium users 2 GB) |
| Audio | 50 MB |
| Animation | 50 MB |