跳至主要内容

自建一个Telegram信息发送Bot

首先要创建一个bot。访问

https://telegram.me/botfather

它会提示你用telegram打开。然后你就打开了botfarther的聊天对话框。输入

/newbot

过程略过,最终记下token (为xxxx:xxxx形式)

我们需要用这个bot来发送消息,首先需要创建一个group,同时将这个bot也加进去,最好设为管理员。然后在这个group中发送消息。类似 /hello @机器人Bot

然后访问

https://api.telegram.org/botxxx:xxx/getUpdates

我们会获取到一个json

{undefined

“ok” : true,

“result” : [{undefined

“update_id” : xxx,

“message” : {undefined

“message_id” : 4,

“from” : {undefined

“id” : xxx,

“first_name” : “david”,

“last_name” : “huang”,

“username” : “davidhuang”

},

“chat” : {undefined

“id” : -xxx,

“title” : “bot”,

“type” : “group”,

“all_members_are_administrators” : true

},

“date” : xxx,

“text” : “/hello @GZ_David_Bot”,

“entities” : [{undefined

“type” : “bot_command”,

“offset” : 0,

“length” : 6

}

]

}

},

]

}

这里,我们看到有个id,指的就是当前group的id。我们记下它 。然后执行以下curl。

botXXX:YYYY 指的是bot+token,一定要加上bot前缀

chat_id就是上面的id,注意是负数,必须有-

发送内容是=MyText

curl -X POST “https://api.telegram.org/botXXX:YYYY/sendMessage” -d “chat_id=-zzzzzzzzzz&text=MyText”

或者在浏览器地址输入:

https://api.telegram.org/botXXX:YYYY/sendMessage?chat_id=-zzzzzzzzzz&text=MyText

群里应该收到信息了。
————————————————
版权声明:本文为CSDN博主「weixin_39917791」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/weixin_39917791/article/details/111520866 

评论

此博客中的热门博文

科学上网工具Sub-Store部署使用

  转自: https://www.qichiyu.com/268.html Openwrt Docker安装: docker run -it -d \ --restart=always \ -e " SUB_STORE_BACKEND_SYNC_CRON =55 23 * * *" \ -e SUB_STORE_FRONTEND_BACKEND_PATH=/CKg2abstVnOeRpm1aB4G \ --net=host \ -v /etc/sub-store:/opt/app/data \ --name sub-store \ xream/sub-store VPS安装: docker run -it -d \ --restart=always \ -e " SUB_STORE_BACKEND_SYNC_CRON =50 23 * * *" \ -e SUB_STORE_FRONTEND_BACKEND_PATH=/T3B9dgzBzdRbBF8Aqx7P \ -p 3001:3001 \ -v /etc/sub-store:/opt/app/data \ --name sub-store \ xream/sub-store Docker compose代码: services: sub-store: stdin_open: true tty: true restart: always environment: - SUB_STORE_BACKEND_SYNC_CRON =50 23 * * * - SUB_STORE_FRONTEND_BACKEND_PATH=/iversonlive123456789 ports: - 3001:3001 volumes: - /etc/sub-store:/opt/app/data container_name: sub-store image: xream/sub-store networks: {} Sub-store地址: 如果你没有使用域名,那么请访问 http://192.168.0.188:3001?api=http://192....

Debian/Ubuntu下MoviePilot V2基本部署

  一,直接用docker-compose: cd /var/lib/docker mkdir -p mp & cd /var/lib/docker/mp (mp可以随意写) 创建一个docker-compose.yml: nano docker-compose.yml 内容如下,自行修改 (文字缩进有问题) (PS. 1,站点认证那里不写也可以,登录后可再认证;2初始密码在log文件中) services: moviepilot: stdin_open: true tty: true container_name: moviepilot-v2 hostname: moviepilot-v2 networks: – moviepilot ports: – target: 3000 published: 3000 protocol: tcp volumes: – /volume1/mp/media:/media – /volume1/mp/config:/config – /volume1/mp/core:/moviepilot/.cache/ms-playwright – /var/run/docker.sock:/var/run/docker.sock:ro environment: – NGINX_PORT=3000 # 别改看下面说明介绍 – PORT=3001 – PUID=0 – PGID=0 – UMASK=000 – TZ=Asia/Shanghai – AUTH_SITE= # 认证站点名称改成自己的 – PTVICOMO_UID= # 认证站点用户ID改成自己的 – PTVICOMO_PASSKEY= # 认证站点秘钥改成自己的 – SUPERUSER=admin # 超级管理员用户名,默认admin改成自己的 # – ‘API_TOKEN=无需手动配置,系统会自动生成。如果需要自定义配置,必须为16位以上的复杂字符串’ restart: always image: jxxghp/moviepilot-v2:latest networks: moviepilot: name: moviepilot 完了后docker-compose up -d。 部署成功后用IP:3000可登录。 二,如果用Dockge,则先装好Dockge(另一...