如何让Telegram Bot发送自定义表情?已尝试方案未生效求助
Telegram Bot 嵌入自定义静态表情问题
我想开发一个能在文本中发送静态自定义表情的Telegram Bot,但找不到有效指导。我为测试Bot设置了webhook,将包含自定义表情的消息转发给Bot后,得到了以下精简后的消息结构:
{ "update_id": 846867202, "message": { "message_id": 68, "from": { "id": <我的ID>, "is_bot": false, "first_name": "Shkiper", "last_name": "Desna" }, "chat": { "id": <我的ID>, "first_name": "Shkiper", "last_name": "Desna", "type": "private" }, "date": 1728164235, "text": "some emoji \ud83e\udd2a in text", "entities": [ { "offset": 11, "length": 2, "type": "custom_emoji", "custom_emoji_id": "5408846744727334338" } ] } }
我参照这个结构构造了JSON请求:
{ "chat_id": <我的ID>, "text": "hello \ud83e\udd2a", "entities": [ { "type": "custom_emoji", "offset": 6, "length": 2, "custom_emoji_id": "5408846744727334338" } ] }
将其保存为mess.json文件后,通过cURL发送请求:
curl https://api.telegram.org/bot<机器人令牌>/sendMessage --header 'Content-Type: application/json' --request POST --data @mess.json
但最终收到的消息只显示普通表情🤪,而非原消息中的自定义表情。请问如何实现Telegram Bot在文本中发送自定义表情?
解决方案
要让Bot在文本中正确发送自定义静态表情,需要调整请求内容并确认权限:
替换文本中的普通emoji为长度2的占位符
Telegram会直接渲染text字段中的普通emoji,不会触发custom_emoji实体的替换逻辑。你需要把对应位置换成两个连续的占位符(比如两个空格),保证长度和entities中的length参数一致(这里是2)。修正实体的offset参数
以调整后的text: "hello "(hello后接两个空格)为例,hello共5个字符(索引0到4),因此两个空格的起始位置是5,对应offset: 5,而非之前的6。
调整后的JSON请求示例:
{ "chat_id": <我的ID>, "text": "hello ", "entities": [ { "type": "custom_emoji", "offset": 5, "length": 2, "custom_emoji_id": "5408846744727334338" } ] }
- 确认Bot的表情访问权限
如果目标自定义表情属于私有贴纸包,必须将Bot添加到该贴纸包所属的频道中,否则Bot无法调用该表情;公开贴纸包则无需额外操作。
使用调整后的请求重新发送,即可在文本中显示目标自定义表情。
内容的提问来源于stack exchange,提问作者ShkiperDesna
相关产品推荐
相关产品推荐

