# 发送Telegram信息

### 图文介绍：

![](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FkCI6oSmNeR1QiTev5Vvy%2Fimage-20210920174443619.png?alt=media\&token=cb69538e-539d-465a-b9b5-f79cd6f7ba94)

![](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2Fak8hbxpdm9yzf5GYyrA2%2Fimage-20210920174941238.png?alt=media\&token=22574e6d-4ae6-4feb-be0e-f091f2a77a7e)

{% hint style="success" %}
访问： [https://api.telegram.org/bot](https://api.telegram.org/bot)\<token>/getUpdates

例如：[https://api.telegram.org/bot2041749079:AAEnuKQzmS-v3jsLlp9fTXUO9yhuE8eZ8ia/getUpdates](https://api.telegram.org/bot2041749079:AAEnuKQzmS-v3jsLlp9fTXUO9yhuE8eZ8ia/getUpdates)
{% endhint %}

![添加机器人到群组](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2F7AxrVERyo8l9kHDjlzhq%2Fimage-20210920174546805.png?alt=media\&token=b10eb3e5-e83f-4a66-a4d2-4926c982329b)

![](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FCywUNBGK8fJc0Npr2vk3%2Fimage-20210920175216468.png?alt=media\&token=df97733b-b1cb-4f45-b7e5-cc5b393f7c71)

![](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FUPjPXp8U0ob5glr7CwsI%2Fimage-20210920175155291.png?alt=media\&token=fa7b657f-2b4f-431a-b4e8-b03c32a5b644)

![添加机器人到群组内， 随便和机器人说话，例如： /aaa @机器人  ，再次访问这个URL页面获取ID](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FwoBq30ZztaU8Dx3vARPS%2Fimage-20210920175410429.png?alt=media\&token=0124fd59-34f8-4e09-b963-bd579de1326b)

##

![](https://2134947750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvILwbD2PrkBCkSitM3m4%2Fuploads%2FSdniJRSDZA1SIIG6AXwc%2Fimage-20210920175601891.png?alt=media\&token=168461cc-7b24-4144-9fb0-30276f18f8c1)



### 代码如下：

{% hint style="info" %}
官方文档： https://core.telegram.org/bots/api

pyTelegramBotAPI GitHub库： https://github.com/eternnoir/pyTelegramBotAPI
{% endhint %}

#### python

`pip install pyTelegramBotAPI`

```python
import telebot
bot = telebot.TeleBot('2041749079:AAEnuKQzmS-v3jsLlp9fTXUxxxxxxx') 
bot.send_message("-555402120", 'Hello world!', parse_mode="Markdown")    # 支持多媒体/图片/声音/HTML/markdown 等类型
```

#### shell

```python
curl -k --data chat_id="-555402120" --data "text=Have a good journey, Mr. Weyland." "https://api.telegram.org/bot<token>/sendMessage"
```
