ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

telegram - api-reference

telegram - api-reference Telegram Bot API - 完整参考目录认证发送方法编辑方法聊天方法成员方法更新与 Webhook机器人配置主要类型解析模式错误代码认证基础 URLhttps://api.telegram.org/botTOKEN/METHOD文件 URLhttps://api.telegram.org/file/botTOKEN/file_path方法GET 和 POST发送参数的方式查询字符串?chat_id123texthelloJSON bodyContent-Type: application/json表单数据Content-Type: application/x-www-form-urlencoded多部分Content-Type: multipart/form-data文件上传必须使用发送方法方法描述必填参数sendMessage文本chat_id、textsendPhoto照片chat_id、photosendVideo视频chat_id、videosendAnimationGIFchat_id、animationsendAudio音频/音乐chat_id、audiosendDocument文档chat_id、documentsendVoice语音消息chat_id、voicesendVideoNote圆形视频chat_id、video_notesendSticker贴纸chat_id、stickersendLocation位置chat_id、latitude、longitudesendVenue地点chat_id、latitude、longitude、title、addresssendContact联系人chat_id、phone_number、first_namesendPoll投票chat_id、question、optionssendDice动画骰子chat_idsendMediaGroup媒体组chat_id、mediasendChatAction打字动作chat_id、actionsendInvoice账单/支付chat_id、title、description、payload、currency、prices所有发送方法共用的参数参数类型描述chat_idInteger/String聊天 ID 或 usernamemessage_thread_idInteger主题 ID论坛中parse_modeStringHTML、MarkdownV2、Markdownreply_parametersObject用于回复某条消息reply_markupObjectInlineKeyboard 或 ReplyKeyboarddisable_notificationBoolean静默发送不通知protect_contentBoolean禁止转发effect_idString消息上的视觉特效sendChatAction - 可用动作typing、upload_photo、record_video、upload_video、record_voice、upload_voice、upload_document、find_location、record_video_note、upload_video_note、choose_sticker编辑方法方法描述editMessageText编辑文本editMessageCaption编辑说明文字editMessageMedia编辑媒体editMessageReplyMarkup编辑按钮deleteMessage删除消息deleteMessages删除多条forwardMessage转发forwardMessages转发多条copyMessage复制无转发自copyMessages复制多条聊天方法方法描述getChat聊天的完整信息getChatMemberCount成员数量getChatAdministrators管理员列表setChatTitle修改标题setChatDescription修改描述setChatPhoto修改照片deleteChatPhoto移除照片setChatPermissions默认权限setChatStickerSet贴纸集pinChatMessage置顶消息unpinChatMessage取消置顶消息unpinAllChatMessages取消置顶全部leaveChat退出聊天exportChatInviteLink生成链接createChatInviteLink创建自定义链接editChatInviteLink编辑链接revokeChatInviteLink撤销链接成员方法方法描述getChatMember成员信息banChatMember封禁unbanChatMember解除封禁restrictChatMember限制promoteChatMember提升为管理员setChatAdministratorCustomTitle自定义头衔approveChatJoinRequest批准入群declineChatJoinRequest拒绝入群更新与 Webhook方法描述getUpdates长轮询setWebhook注册 webhookdeleteWebhook移除 webhookgetWebhookInfowebhook 状态更新类型message、edited_message、channel_post、edited_channel_post、inline_query、chosen_inline_result、callback_query、shipping_query、pre_checkout_query、poll、poll_answer、my_chat_member、chat_member、chat_join_request、message_reaction、message_reaction_count机器人配置方法描述getMe机器人信息setMyCommands定义命令getMyCommands列出命令deleteMyCommands移除命令setMyName修改名称setMyDescription修改描述setMyShortDescription简短描述setMyDefaultAdministratorRights默认管理员权限setChatMenuButton菜单按钮setMyProfilePhoto个人资料照片主要类型Update{update_id:123,message:{...},callback_query:{...},inline_query:{...}}Message{message_id:1,from:{id:123,first_name:User},chat:{id:123,type:private},date:1709000000,text:Hello,entities:[{type:bot_command,offset:0,length:6}]}CallbackQuery{id:query123,from:{id:123},message:{...},data:callback_data_string}InlineKeyboardMarkup{inline_keyboard:[[{text:Button,callback_data:data}],[{text:URL,url:https://example.com}]]}ReplyKeyboardMarkup{keyboard:[[{text:Option 1},{text:Option 2}],[{text:Send Location,request_location:true}]],resize_keyboard:true,one_time_keyboard:true}解析模式HTMLbbold/biitalic/iuunderline/usstrikethrough/stg-spoilerspoiler/tg-spoilercodeinline code/codeprepreformatted/preprecodeclasslanguage-pythonpython code/code/preahrefhttps://example.comlink/aahreftg://user?id123user mention/ablockquotequote/blockquoteMarkdownV2*bold* _italic_ __underline__ ~strikethrough~ ||spoiler|| inline code pre block python python codelinkuserblockquote**MarkdownV2 中需要转义的字符** _ * [ ] ( ) ~ # - | { } . ! --- ## 错误代码 | 代码 | 描述 | 应对 | |--------|-----------|------| | 400 | Bad Request - 参数无效 | 检查参数 | | 401 | Unauthorized - 令牌无效 | 检查令牌 | | 403 | Forbidden - 机器人被屏蔽 | 用户屏蔽了机器人 | | 404 | Not Found - 方法无效 | 检查方法名称 | | 409 | Conflict - webhook 和轮询冲突 | 只使用一种方法 | | 429 | Too Many Requests - 速率限制 | 等待 retry_after 秒 | ### 常见错误消息 - chat not found - 聊天 ID 无效或机器人未启动 - bot was blocked by the user - 用户屏蔽了机器人 - message to edit not found - 消息已被删除 - query is too old - 回调查询已过期需在 10 秒内响应 - message is not modified - 文本与之前相同 - BUTTON_DATA_INVALID - callback_data 64 字节 - have no rights to send a message - 机器人在群组中没有权限
返回列表