电报 API

我们为开发者提供三种 API。Bot API允许您轻松创建使用 Telegram 消息作为界面的程序。Telegram API 和 TDLib允许您构建自己的自定义 Telegram 客户端。欢迎您免费使用这两种 API。最后,Gateway API允许任何企业、应用程序或网站通过 Telegram 发送验证码,而不是传统的短信。

您还可以将Telegram Widgets添加到您的网站。

欢迎设计师为 Telegram创建动画贴纸自定义主题。

机器人 API

此 API 允许您将机器人连接到我们的系统。Telegram机器人是特殊帐户,无需设置额外的电话号码。这些帐户可作为在您的服务器上某处运行的代码的接口。

要使用此功能,您无需了解我们的 MTProto 加密协议的工作原理——我们的中介服务器将为您处理所有加密和与 Telegram API 的通信。您可以通过一个简单的 HTTPS 接口与此服务器通信,该接口提供简化版的 Telegram API。

在此处了解有关 Bot API 的更多信息 »

机器人开发人员还可以利用我们的支付 API接受来自世界各地 Telegram 用户的付款。

TDLib – 构建你自己的 Telegram

即使您希望实现最大程度的自定义,也不必从头开始创建应用。尝试我们的Telegram 数据库库(简称 TDLib),这是一款面向第三方开发人员的工具,可让您轻松构建快速、安全且功能丰富的 Telegram 应用。

TDLib 负责所有网络实现细节、加密本地数据存储,以便您可以投入更多时间进行设计、响应式界面和精美的动画。

TDLib 支持所有 Telegram 功能,使在任何平台上开发 Telegram 应用变得轻而易举。它可以在 Android、iOS、Windows、macOS、Linux 和几乎任何其他系统上使用。该库是开源的,并且与几乎任何编程语言兼容。

在此了解有关 TDLib 的更多信息 »

网关 API

Telegram Gateway API 允许任何企业、应用或网站通过 Telegram 发送授权代码,而不是通过传统的短信发送授权代码,这是一种强大而便捷的方式,可以降低成本,同时提高代码的安全性和向 Telegram 每月 9.5 亿活跃用户发送代码的速度。用户将立即在 Telegram 内的特殊聊天中收到带有代码的消息。

Telegram 的 Gateway API 完全免费测试。点击此处了解更多信息 »

电报API

此 API 允许您构建自己的自定义 Telegram 客户端。它对所有希望在我们的平台上创建 Telegram 应用程序的开发人员完全开放。您可以随意研究现有 Telegram 应用程序的开源代码,以了解这里的工作原理。不要忘记在我们的系统中注册您的应用程序。

入门

创建应用程序

如何获取您的应用程序标识符并创建新的 Telegram 应用程序。

用户授权

如何注册用户电话以开始使用 API。

双重身份验证

如果用户启用了 2FA,如何登录用户帐户,如何更改密码。

二维码登录

二维码登录流程

错误处理

如何正确处理API返回错误。

处理不同的数据中心

如何连接最近的DC接入点,以便更快地与API交互,以及开发客户端时需要注意的事项。

处理更新

如何订阅更新并正确处理它们。

处理推送通知

如何订阅并正确处理它们。

频道、超级组、千兆组和基本组

如何处理频道、超级组、千兆组、基本组,以及它们之间的区别是什么。

论坛

Telegram 允许创建包含多个不同主题的论坛。

渠道统计

Telegram 提供频道和超级群组的详细频道统计数据。

调用方法

调用方法的附加选项。

上传和下载文件

如何正确传输大量数据。

分页

如何从大量对象中获取结果。

客户端配置

MTProto API 有多个客户端配置参数,可以使用适当的方法获取。

安全

秘密聊天,端到端加密

端到端加密消息传递。

安全指南

您的客户端应用程序中需要进行的重要检查。

完美前向保密

将临时授权密钥与永久授权密钥绑定。

语音和视频通话中的端到端加密

端到端加密通话。

优化

客户端优化

增强 API 交互的方法。

API 方法

可用方法列表

可用的高级方法的列表。

API TL 模式作为 JSON

API 中使用的类型和方法的文本和 JSON 表示。

可用图层列表

可用架构版本的列表。

其他文章

使用 MTProto API 与机器人合作

如何使用 MTProto API 与机器人合作。

命令

机器人提供了一组命令,可供用户私下或聊天时使用。

按钮

用户可以通过按钮甚至内联按钮与您的机器人进行交互,直接从任何聊天中的内联消息进行交互。

菜单按钮

机器人可以选择文本输入字段旁边显示的菜单按钮的行为。

内联查询

Users can interact with your bot via inline queries, straight from the text input field in any chat.

Games

Bots can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats; how to work with games in the MTProto API.

Mini apps

Bots can offer users interactive HTML5 mini apps to completely replace any website.

Attachment menu

Bots can install attachment menu entries, offering conveniently accessible, versatile mini apps.

Stories

Telegram users and channels can easily post and view stories through the API.

Similar channels

The API offers a method to obtain a list of similarly themed public channels, selected based on similarities in their subscriber bases.

Accent colors

Telegram users and channels can change the accent color and background pattern of their profile page and their messages!

Privacy settings

Telegram allows users to specify granular privacy settings, choosing which users can or can’t interact with them in certain ways.

Search & filters

Telegram allows applying detailed message filters while looking for messages in chats.
This allows the server to filter messages based on a text query, and even on their type, and this feature is often used by graphical clients to implement features like the chat gallery, chat profile pictures and more.

Polls

Telegram allows sending polls and quizzes, that can be voted on by thousands, if not millions of users in chats and channels.

Reactions

Telegram allows users to react on any message using specific emojis, triggering cute lottie animations.

Animated message effects

Telegram allows adding spectacular animated effects to messages you send.

Emoji categories

Sticker, custom emoji and GIF selection UIs should offer a list of categories to quickly filter results by a (list of) emojis, or by some other criteria.

Emoji status

Telegram allows users to set an emoticon or a custom emoji as status, to show next to their name in chats and profiles.

Invite links and join requests

Channels, basic groups and supergroups may have a public username or a private invite link: private invite links may be further enhanced with per-user join requests.

Admin, banned and default rights for channels, supergroups and groups

How to handle admin permissions, granular bans and global permissions in channels, groups and supergroups.

Discussion groups

Groups can be associated to a channel as a discussion group, to allow users to discuss about posts.

Channel comments and message threads

Telegram allows commenting on a channel post or on a generic group message, thanks to message threads.

Admin log

Both supergroups and channels offer a so-called admin log, a log of recent relevant supergroup and channel actions, like the modification of group/channel settings or information on behalf of an admin, user kicks and bans, and more.

Pinned messages

Telegram allows pinning multiple messages on top of a specific chat.

Mentions

Telegram allows mentioning other users in case of urgent duckling matters, and quickly navigating to those mentions in order to read them as swiftly as possible.

Scheduled messages

Telegram allows scheduling messages.

Live geolocations

Telegram allows sending the live geolocation of a user in a chat, optionally setting a proximity alert.

Peer database

How to work with peer information in the API.

Min constructors

Sometimes, user and channel constructors met in group chat updates may not contain full info about the user: how to handle such constructors.

Account deletion

How to delete a Telegram account.

Imported messages

Telegram allows importing messages and media from foreign chat apps.

Telegram Passport

How to work with Telegram Passport directly using the MTProto API.

Telegram Payments

How to work with Telegram Payments directly using the MTProto API.

Styled text with message entities

How to create styled text with message entities

Working with GIFs

Telegram clients support displaying GIFs.

Working with stickers

Telegram clients support displaying animated, static and video stickers.

Working with custom emojis

Telegram allows including custom animated, static and video emojis directly inside of messages.

Working with animated emojis

Graphical telegram clients should transform emojis into their respective animated version.

Working with animated dice

Telegram supports sending animated dice emojis.

Message drafts

How to handle message drafts

Folders

Working with folders

Top peer rating

If enabled, the rating of top peers indicates the relevance of a frequently used peer in a certain category (frequently messaged users, frequently used bots, inline bots, frequently visited channels and so on).

Handling file references

How to handle file references.

Seamless Telegram Login

Handle Seamless Telegram Login URL authorization requests.

Wallpapers

How to work with chat backgrounds.

Notification sounds

How to work with chat notification sounds.

Message transcription

How to transcribe voice messages.

Message translation

Telegram allows translating chat messages, and Telegram Premium users may even enable real-time chat translation.

Native antispam system

Admins of supergroups with a certain number of members can choose to unleash the full proactive power of Telegram’s own antispam algorithms – turning on the new Aggressive mode for the automated spam filters.

Collectibles

Telegram users can make it easy for others to contact them or find their public groups and channels via usernames: clients can also assign multiple Fragment » collectible usernames to accounts, supergroups and channels they own; Fragment » also allows purchasing phone number collectibles that can be used to register Telegram accounts.

Telegram Premium

Telegram Premium is an optional subscription service that unlocks additional exclusive client-side and API-side features, while helping support the development of the app. It is a part of Telegram’s sustainable monetization – driven by our users, rather than advertisers or shareholders. This way, Telegram can remain independent and prioritize its users first.

Telegram Business

Users can turn their Telegram account into a business account, gaining access to business features such as opening hours, location, quick replies, automated messages, custom start page, chatbot support, and more.

For the moment, all Telegram Business features are available for free to Telegram Premium subscribers.

Telegram Stars

Telegram Stars are virtual items that allow users to purchase digital goods and services from bots and mini apps inside the Telegram ecosystem, send gifts to content creators on the Telegram platform, and more.

Paid media

Content creators can accept Stars by publishing paid photos or videos on their channels. Subscribers will be allowed to view such posts only after paying the author to unlock them.

Channel and supergroup boosts

Telegram Premium users can grant their favorite channels additional features like the ability to post stories by giving them boosts.

Giveaways & gifts

Telegram channel administrators may launch giveaways to randomly distribute Telegram Premium subscriptions and other gifts among their followers, in exchange for boosts.

Action bar

Sometimes, when interacting with Telegram users via private or secret chats, an action bar must be shown on top of the chat, offering convenient action buttons or notices regarding the user.

Saved messages

The Saved Messages chat allows users to bookmark messages and media: it’s a personal cloud storage for any messages or media you may want to send or forward there.

Profile

Telegram offers many customization options for your profile!

Themes

Telegram apps support generating, sharing and synchronizing app themes.

Sponsored messages

If your app allows accessing content from Telegram channels, you must include support for official sponsored messages in Telegram channels.

Channel ad revenue

Telegram 拥有社交媒体历史上最慷慨的奖励制度之一。Telegram 频道所有者现在可以获得其频道中展示的广告收入的50% 。

本页介绍了提取频道广告收入的方法,以及查看详细的收入统计数据。

事实核查

Telegram 客户端支持显示独立事实核查人员添加到消息中的事实核查。

联系方式

使用 API 中的联系人。

阻止列表

使用阻止列表。

附近的用户和聊天

如何使用基于地理位置的功能,例如 geochats 和附近的用户功能。

Web 事件

在与 HTML5 游戏和支付网关网站交互时,Telegram 应用程序应公开以下 JS API。

深层链接

Telegram 客户端必须通过注册操作系统处理程序来处理消息、链接实体和其他应用中遇到的特殊tg://和深层链接。t.me

取出

Telegram 的 API 允许用户通过外卖 API 导出自己的所有信息。

滚动至顶部