{"id":3415,"date":"2018-02-01T14:07:47","date_gmt":"2018-02-01T06:07:47","guid":{"rendered":"https:\/\/dmesg.app\/?p=3415"},"modified":"2019-10-31T20:06:58","modified_gmt":"2019-10-31T12:06:58","slug":"tgbot1","status":"publish","type":"post","link":"https:\/\/dmesg.app\/tgbot1.html","title":{"rendered":"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282"},"content":{"rendered":"<div  class=\"sc_act\">\u8fd9\u7bc7\u6587\u7ae0\u5728 2019\u5e7410\u670831\u65e520:06:58 \u66f4\u65b0\u4e86\u54e6~<\/div><p><span style=\"font-size: 12pt;\">\u53c8\u5230\u4e86\u4e00\u5e74\u4e00\u5ea6\u5199\u201c\u65b0\u5e74\u9996\u535a\u201d\u7684\u65f6\u5019\uff01\u5f88\u9ad8\u5174\uff0c\u672c\u535a\u5ba2\u4f9d\u7136\u575a\u633a\uff0c\u6b63\u52aa\u529b\u5411\u7740\u3010\u4e09\u5468\u5e74\u3011\u5e86\u5178\u4e00\u5929\u5929\u5730\u8fc8\u8fdb\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u5173\u4e8e\u4ffa\u8fd1\u671f\u7684\u9759\u9ed8<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u6700\u8fd1\u4e00\u4e2a\u591a\u6708\uff0c\u4ffa\u786e\u5b9e\u6bd4\u8f83\u5fd9\uff08\u5728\u524d\u51e0\u7bc7\u535a\u6587\u4e2d\u4e5f\u591a\u6b21\u63d0\u53ca\u8fd9\u70b9\uff09\uff0c\u5bfc\u81f4\u535a\u5ba2\u66f4\u65b0\u9891\u7387\u4e0b\u964d\u3002\u5728\u6b64\uff0c\u5148\u5411\u5404\u4f4d\u8bfb\u8005\u8868\u793a\u62b1\u6b49 <img src=\"https:\/\/dmesg.app\/wp-content\/themes\/WordPressGit-master\/css\/img\/smilies\/icon_sad.gif\" alt=\":(\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e3a\u4e86\u907f\u514d\u5927\u4f19\u513f\u65e0\u8c13\u7684\u62c5\u5fc3\uff0c<del>\u4ffa\u5c3d\u91cf\u628a\u9759\u9ed8\u7684\u65f6\u95f4\u8de8\u5ea6\u63a7\u5236\u5728\u301014\u5929\u3011\u4e4b\u5185\uff0c\u4ee5\u8868\u660e\u4ffa\u81ea\u5df1\u662f\u5b89\u5168\u7684\uff08\u8fd9\u662f\u524d\u51e0\u5e74\u5728\u535a\u5ba2\u4e2d\u505a\u7684\u7ea6\u5b9a\uff09\u3002<\/del><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0a\u4e00\u7bc7\u535a\u6587\u662f\u57282017\u5e74\u6700\u540e\u51e0\u5929\u53d1\u51fa\u7684\uff0c\u6628\u5929\uff081\u670831\u65e5\uff09\u4ffa<s>\u7279\u5730<\/s>\u4e0a\u535a\u5ba2\u56de\u590d\u4e86\u4e00\u4e9b\u8bc4\u8bba\u2014\u2014<s>\u6240\u4ee5\u8fd9\u6b21\u9759\u9ed8\u7684\u65f6\u95f4\u3010\u6ca1\u6709\u3011\u8d85\u8fc714\u5929\u3002<\/s><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u5c0f\u571f\u8c46\u673a\u5668\u4eba\u8bfe\u7a0b\u53c8\u5f00\u8bfe\u5566<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u81ea\u4ece\u4e09\u4e2a\u6708\u524d\u53d1\u51fa\u7b2c\u4e00\u7bc7<a href=\"https:\/\/dmesg.app\/tgbot0.html\">\u300a[Telegram bot \u7cfb\u5217]0\uff1a\u7528 Python \u5199\u4e00\u4e2a Telegram Bot \u7b80\u5355\u7684\u56de\u8bdd bot\u300b<\/a>\uff0c\u8fd9\u4e00\u7cfb\u5217\u5c31\u597d\u50cf\u662f\u53f2\u4e0a\u6700\u4e0d\u53d7\u5f85\u89c1\u7684\u7cfb\u5217\u4e00\u6837\uff1a\u6ca1\u4eba\u770b\uff0c\u4e5f\u6ca1\u6709\u5565\u60f3\u5199\u7684\u6b32\u671b\uff0c\u66f4\u91cd\u8981\u7684\u662f\u4e5f\u6ca1\u65f6\u95f4\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e8e\u662f\u4e4e\uff0c\u968f\u7740<a href=\"https:\/\/t.me\/bennyblog_bot\">ExpressBot<\/a>\u8d8a\u6765\u8d8a\u597d\u73a9\uff0c\u8d81\u7740\u8fd9\u51e0\u5929\u6709\u65f6\u95f4\uff0c\u6211\u51b3\u5b9a\u7ed9\u8fd9\u4e00\u7cfb\u5217\u6ce8\u5165\u65b0\u9c9c\u7684\u8840\u6db2\uff0c\u518d\u6b21<s>\u5f00\u8bfe<\/s>\u6c34\u8d34\uff0c\u8bf4\u4e0d\u5b9a\u672c\u7cfb\u5217\u5c31\u8fd9\u4e48\u77ed\u547d\u7684\u88ab\u6211\u5728\u6b64\u7bc7\u4e2d\u7ec8\u7ed3\u5566\u266a(^\u2207^*)\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u673a\u5668\u4eba<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\"><a href=\"https:\/\/twitter.com\/BennyThinks\/status\/956079273835560960\">\u51e0\u5929\u524d<\/a>\u88ab\u544a\u77e5\u6211\u7684\u673a\u5668\u4eba\u4e0a\u4e86\u5c11\u6570\u6d3e\uff1a<a href=\"https:\/\/sspai.com\/post\/42967\">\u300a\u67e5\u5feb\u9012\u3001\u6536\u90ae\u4ef6\u3001\u8ba2\u9605 RSS\u2026\u2026\u9664\u4e86\u804a\u5929 Telegram \u8fd8\u6709\u8fd9\u4e9b\u5b9e\u7528\u529f\u80fd\u300b<\/a>\uff0c \u7136\u540e\u7528\u6237\u6570\u91cf\u5927\u589e\uff0c\u5bfc\u81f4<a href=\"https:\/\/twitter.com\/BennyThinks\/status\/956264608561377280\">\u88ab\u5feb\u9012100\u5c01IP<\/a>\uff0c\u7136\u540e\u2026\u2026\u8fd9\u51e0\u5929\u62bd\u51fa\u6765\u65f6\u95f4\uff0c\u6084\u6084\u7684\u7ed9\u673a\u5668\u4eba\u52a0\u4e86\u4e00\u4e9b<s>\u6539\u8fdb<\/s>\u9650\u5236\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u5185\u8054\u952e\u76d8\uff08Inline Keyboard\uff09\u4e0e\u56de\u590d\u952e\u76d8\uff08Reply Keyboard\uff09<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u7528\u8fc7BotFather\u7684\u4eba\u53ef\u80fd\u8bb0\u5f97\uff0c\u521b\u5efa\u673a\u5668\u4eba\u7684\u65f6\u5019\u6211\u4eec\u80fd\u770b\u5230\u8fd9\u6837\u7684\u6309\u94ae\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"342\" height=\"189\" class=\"wp-image-3416\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105133426.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u54b1\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u6309\u94ae\u6765\u548c\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\uff0c\u6709\u4e9b\u6309\u94ae\u8fd8\u53ef\u4ee5\u662f\u94fe\u63a5\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"580\" class=\"wp-image-3417\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105133615.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" alt=\"https:\/\/core.telegram.org\/file\/811140999\/1\/2JSoUVlWKa0\/4fad2e2743dc8eda04\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0a\u56fe\u8fd9\u79cd\u65b9\u5f0f\u6211\u4eec\u79f0\u4e4b\u4e3aInline Keyboard\u3002\u70b9\u51fbInline Keyboard\u7684\u6309\u94ae\u4e0d\u4f1a\u9020\u6210\u5ba2\u6237\u7aef\u5411\u673a\u5668\u4eba\u53d1\u9001\u6d88\u606f<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd8\u6709\u4e00\u79cd\u4e0eInline Keyboard\u6bd4\u8f83\u63a5\u8fd1\u7684\u662fcustom Reply Keyboard\uff0c\u50cf\u4e0b\u56fe\u8fd9\u6837\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"826\" class=\"wp-image-3418\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105133792.jpeg\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" alt=\"https:\/\/core.telegram.org\/file\/811140880\/1\/jS-YSVkDCNQ\/b397dfcefc6da0dc70\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u7528\u6237\u70b9\u51fb\u6587\u672c\u7f16\u8f91\u6846\u4e0b\u9762\u7684\u6309\u94ae\uff0c\u5ba2\u6237\u7aef\u5c31\u4f1a\u81ea\u52a8\u4e3a\u6211\u4eec\u53d1\u9001\u5bf9\u5e94\u7684\u6d88\u606f\uff0c\u5b9e\u9645\u4e0aReply Keyboard\u66f4\u50cf\u662f\u5feb\u6377\u56de\u590d\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u4e24\u79cdkeyboard\u975e\u5e38\u9002\u5408\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\uff08\u6bd4\u5982\u8bf4\u6e38\u620f\uff09\uff0c\u5e76\u4e14\u7528\u6237\u4e0d\u7528\u4e00\u6b21\u6027\u5b8c\u6574\u7684\u8f93\u5165\u547d\u4ee4\u3001\u670d\u52a1\u7aef\u4e00\u6b21\u6027\u5b8c\u6210\u89e3\u6790\u547d\u4ee4\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u89c2\u5bdf\u4ed4\u7ec6\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u80fd\u53d1\u73b0\uff0c<a href=\"https:\/\/t.me\/bennyblog_bot\">ExpressBot<\/a> \u7684\u67e5\u8be2\u7f8e\u5267\u529f\u80fd\u7a81\u7136\u53d8\u5f97\u66f4\u597d\u7528\u4e00\u4e9b\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"304\" class=\"wp-image-3419\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105133848.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">Reply Keyboard\u6570\u636e\u7ed3\u6784\u53ca\u7b80\u5355\u793a\u4f8b<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u6570\u636e\u7ed3\u6784<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"900\" class=\"wp-image-3420\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/201802010513382.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 10pt;\">\u56fe\u7247\u622a\u56fe\u81ea<a href=\"https:\/\/core.telegram.org\/bots\/api#replykeyboardmarkup\">Telegram\u5b98\u7f51<\/a><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6211\u89c9\u5f97\u5927\u5bb6\u90fd\u80fd\u770b\u61c2\u8fd9\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u90a3\u4e48\u5c31\u5199\u4e00\u4e2a\u7b80\u5355\u7684Reply Keyboard\u5427\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u7b80\u5355\u793a\u4f8b1\uff1aReply Keyboard<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u4e3a\u4e86\u5e94\u7528Reply Keyboard\uff0c\u6211\u4eec\u9700\u8981\u5728send_xyz\u4e2d\u7ed9\u53c2\u6570reply_markup\u4f20\u9012\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u952e\u76d8\uff0c\u5176\u4e2dreply_markup\u5fc5\u987b\u662fReplyKeyboardMarkup\uff08\u81ea\u5b9a\u4e49\u7684\u952e\u76d8\uff09\u3001ReplyKeyboardRemove\uff08\u79fb\u9664\u952e\u76d8\uff09\u6216ForceReply\uff08\u5f3a\u5236\u7528\u6237\u56de\u590d\uff09\u7684\u5b9e\u4f8b\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u9996\u5148\u6211\u4eec\u9700\u8981\u5f15\u5165types<\/span><\/p>\n<pre class=\"prettyprint linenums\">from telebot import types\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u4e4b\u540e\u76f4\u63a5\u5f00\u59cb\u5199\u5bf9\u5e94\u547d\u4ee4\u7684\u4ee3\u7801\u5c31\u53ef\u4ee5\u4e86\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">@bot.message_handler(commands=[&#039;start&#039;])\r\ndef send_welcome(message):\r\n    markup = types.ReplyKeyboardMarkup(row_width=2)\r\n    itembtn1 = types.KeyboardButton(&#039;a&#039;)\r\n    itembtn2 = types.KeyboardButton(&#039;v&#039;)\r\n    itembtn3 = types.KeyboardButton(&#039;d&#039;)\r\n    markup.add(itembtn1, itembtn2, itembtn3)\r\n    bot.send_message(message.chat.id, &quot;Choose one letter:&quot;, reply_markup=markup)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u5148\u5b9a\u4e49\u4e86\u4e00\u4e2amarkup\u5b9e\u4f8b\uff0c\u8bbe\u7f6e\u884c\u5bbd\u4e3a2\uff0c\u7136\u540e\u6dfb\u52a0avd\u4e09\u4e2a\u6309\u94ae\uff0c\u4e4b\u540e\u5728<code>send_message<\/code>\u7684<code>reply_markup<\/code>\u4e2d\u4f20\u9012markup\u5b9e\u4f8b\u3002\u5982\u679c\u9700\u8981\u70b9\u51fb\u4e00\u6b21\u5c31\u9690\u85cf\u7684\u952e\u76d8\uff08\u4f46\u662f\u4f9d\u65e7\u53ef\u4ee5\u70b9\u51fb\u6309\u94ae\u663e\u793a\uff09\uff0c\u90a3\u4e48\u53ef\u4ee5\u7ed9markup\u6784\u9020\u65f6\u52a0\u5165<code>one_time_keyboard=True<\/code>\u7684\u53c2\u6570\u3002<\/span><\/p>\n<div id=\"sc_blue\"><span style=\"font-size: 12pt;\">\u5173\u4e8erow_width\u7684\u6ce8\u610f\u4e8b\u9879\uff1a<br \/>\n\u5bf9\u4e8eReplyKeyboard\u548c\u4e0b\u9762\u5373\u5c06\u63d0\u5230\u7684InlineKeyboard\u6765\u8bf4\uff0c\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u662f\u901a\u8fc7\u5faa\u73af\u52a8\u6001\u751f\u6210\u7684button\uff0c\u5e76\u4e14\u5728\u5faa\u73af\u4e2d\u8fed\u4ee3\u8c03\u7528<code>markup.add(btn)<\/code>\uff0c\u90a3\u4e48\u6700\u7ec8\u53ea\u4f1a\u4e00\u4e2a\u6309\u94ae\u4e00\u6392\u3002\u8fd9\u662f\u56e0\u4e3a<code>markup.add(btn1,btn2,btn3)<\/code>\u8fd9\u4e09\u4e2a\u624d\u4f1a\u88ab\u8ba4\u4e3a\u4e00\u7ec4\u653e\u5230\u4e00\u6392\uff0c\u800c<code>markup.add(btn)<\/code>\u8fed\u4ee3\u4e09\u6b21\u4f1a\u88ab\u8ba4\u4e3a\u662f\u4e09\u7ec4\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5982\u679c\u60f3\u8981\u9075\u5faarow_width\u7684\u8bbe\u7f6e\uff0c\u90a3\u4e48\u9700\u8981\u5c06\u6309\u94aeappend\u5230\u4e00\u4e2a\u5217\u8868\u91cc\uff0c\u7136\u540e\u5bf9\u5217\u8868\u6309\u7167row_width\u8fdb\u884c\u5207\u7247\uff0c\u4e4b\u540e\u5224\u65ad\u6267\u884cN\u4e2a\u53c2\u6570\u7684<code>markup.add()<\/code>\u3002\u8be6\u7ec6\u7684\u4ee3\u7801\u53ef\u4ee5<a href=\"https:\/\/github.com\/BennyThink\/ExpressBot\/commit\/853b3cec9cc0aa1f2f3b9b362650a4c91fbb4ac3\" target=\"_blank\" rel=\"noopener noreferrer\">\u53c2\u8003\u8fd9\u6bb5commit<\/a><\/span><\/div>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"635\" height=\"252\" class=\"wp-image-3421\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105133948.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5982\u679c\u6211\u4eec\u9700\u8981\u70b9\u51fb\u6309\u94ae\u5206\u4eab\u7535\u8bdd\u53f7\u7801\u3001\u5730\u7406\u4f4d\u7f6e\uff0c\u90a3\u4e48\u53ef\u4ee5\u6784\u9020\u6309\u94ae\u7684\u65f6\u5019\u52a0\u5165\u5bf9\u5e94\u7684\u53c2\u6570\uff0c\u5982 <code>itembtn1 = types.KeyboardButton('a', request_contact=True)<\/code>\uff0c\u6b64\u65f6\u70b9\u51fb\u6309\u94ae\uff0c\u4f1a\u6709\u7c7b\u4f3c\u5982\u4e0b\u7684\u63d0\u793a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"512\" height=\"234\" class=\"wp-image-3422\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/201802010513397.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u7b80\u5355\u793a\u4f8b2\uff1aReplyKeyboardRemove<\/span><\/h3>\n<pre class=\"prettyprint linenums\">markup = types.ReplyKeyboardRemove(selective=False)\r\ntb.send_message(chat_id, message, reply_markup=markup)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u53d1\u9001\u8fd9\u4e2amarkup\u4f1a\u79fb\u9664\u81ea\u5b9a\u4e49\u952e\u76d8<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u7b80\u5355\u793a\u4f8b3\uff1aForceReply<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">ForceReply\u662f\u5f3a\u5236\u56de\u590d\uff0c\u5c31\u597d\u50cf\u7528\u6237\u56de\u590d\u673a\u5668\u4eba\u7684\u6d88\u606f\u4e00\u6837\uff0c\u4f7f\u7528\u65b9\u6cd5\u4e5f\u5f88\u7b80\u5355\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">markup = types.ForceReply()\r\nbot.send_message(message.chat.id, &quot;Choose one letter:&quot;, reply_markup=markup)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"629\" height=\"168\" class=\"wp-image-3423\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134043.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">Inline Keyboard\u4e4b\u6570\u636e\u7ed3\u6784<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"807\" height=\"1095\" class=\"wp-image-3424\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134013.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6211\u731c\u5927\u5bb6\u4e5f\u90fd\u80fd\u770b\u61c2\u3002InlineKeyboardMarkup\u7684\u6784\u9020\u6bd4\u8f83\u7b80\u5355\uff0cInlineKeyboardButton\u7684\u53c2\u6570\u8981\u7a0d\u5fae\u590d\u6742\u4e00\u70b9\uff0c\u5176\u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u6709\uff1a<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 12pt;\">text \u6309\u94ae\u4e0a\u663e\u793a\u7684\u6587\u5b57<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">url \u70b9\u51fb\u6309\u94ae\u65f6\u6253\u5f00\u7684url<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">callback_data \u56de\u8c03\u6570\u636e\uff0c1-64\u5b57\u8282\u3002<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-size: 12pt;\">Inline Keyboard\u4e4bCallbackQuery\u4e0eanswerCallbackQuery<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u7531\u4e8e\u70b9\u51fbInlineKeyboard\u65f6\u5e76\u4e0d\u662f\u53d1\u9001\u5e38\u89c4\u7684\u547d\u4ee4\uff08\/start\uff09\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5904\u7406Callback\uff0cTelegram\u4f7f\u7528CallbackQuery\u6765\u5904\u7406\u6b64\u7c7b\u8bf7\u6c42\uff0c\u5176\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"519\" class=\"wp-image-3425\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134137.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5176\u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u6709\uff1a<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 12pt;\">id \u552f\u4e00\u6807\u8bc6\u6b64\u6b21\u6309\u94ae\u70b9\u51fb<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">message \u89e6\u53d1\u6b64\u6b21callback\u7684\u6d88\u606f\uff0c\u5176\u6570\u636e\u7ed3\u6784\u4e3aMessage\u7c7b\u578b\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528message.chat.id\u7b49\u65b9\u6cd5<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">data callback_data\u4e2d\u7684\u5b57\u7b26\u4e32<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 12pt;\">\u5f53\u7528\u6237\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6309\u94ae\u65c1\u8fb9\u4f1a\u663e\u793a\u4e00\u4e2a\u52a0\u8f7d\u4e2d\u7684\u56fe\u6807\uff0c\u6b64\u65f6\u5efa\u8bae\u4f7f\u7528answerCallbackQuery\u6765\u7ed9\u7528\u6237\u63d0\u793a\u4fe1\u606f\uff0c\u5176\u6570\u636e\u7ed3\u6784\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"597\" class=\"wp-image-3426\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134239.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">Inline Keyboard \u53ca\u56de\u8c03\u7b80\u5355\u793a\u4f8b<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u8bf4\u4e86\u90a3\u4e48\u591a\u6570\u636e\u7ed3\u6784\u53ef\u80fd\u4f1a\u6709\u70b9\u61f5?\uff0c\u90a3\u4e48\u8fd8\u662f\u76f4\u63a5\u4e0a\u4ee3\u7801\u66f4\u723d\u5427~<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u50cf\u5f80\u5e38\u4e00\u6837\uff0c\u521b\u5efaInlineKeyboard\u5b9e\u4f8b\uff0c\u521b\u5efa\u952e\u76d8\u5b9e\u4f8b\uff0c\u7136\u540e\u5728send_xyz\u4e2d\u628amarkup\u53d1\u9001\u8fc7\u53bb\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">markup = types.InlineKeyboardMarkup()\r\nbtn1 = types.InlineKeyboardButton(&#039;Google&#039;, url=&#039;https:\/\/www.google.com\/ncr&#039;)\r\nbtn2 = types.InlineKeyboardButton(&#039;Action&#039;, callback_data=&#039;Act Now&#039;)\r\nmarkup.add(btn1,btn2)\r\nbot.send_message(message.chat.id, &quot;InlineKeyboard: &quot;, reply_markup=markup)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u6309\u94ae1\u662f\u6253\u5f00Google\uff0c\u6309\u94ae2\u9700\u8981\u6211\u4eec\u5904\u7406\u56de\u8c03\uff0c\u53ef\u4ee5\u8fd9\u4e48\u73a9\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">@bot.callback_query_handler(func=lambda call: True)\r\ndef callback_handle(call):\r\n    bot.answer_callback_query(call.id, &#039;\u54ce\u54df&#039;)\r\n    bot.send_message(call.message.chat.id, &#039;You clicked %s&#039; % call.data)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u628a\u8fd9\u4e24\u6bb5\u7ed3\u5408\u8d77\u6765\uff0c\u8fd0\u884c\u7684\u8bdd\u6548\u679c\u5927\u6982\u662f\u9171\u7d2b\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u56de\u8c03\u51fd\u6570\u4e2d<code>call.data<\/code>\u5c31\u662f\u6211\u4eec\u5728\u5b9e\u4f8b\u5316InlineKeyboardButton\u4e2d\u53c2\u6570callback_data\u6240\u8bbe\u7f6e\u7684\u503c\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"266\" class=\"wp-image-3427\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134342.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5982\u679cAnswerCallbackQuery\u5f00\u59cb\u4e86showAlert\u7684\u8bdd\uff0c\u90a3\u4e48\u4f1a\u5982\u4e0b\u5f39\u7a97\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"637\" height=\"261\" class=\"wp-image-3428\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134339.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u66f4\u65b0\u6d88\u606f\uff1a\u7f16\u8f91\u6d88\u606f\uff08editMessageText\uff09\u3001\u5220\u9664\u6d88\u606f\uff08deleteMessage\uff09\u4e0e\u7f16\u8f91markup\uff08editMessageReplyMarkup\uff09<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u77e5\u9053\uff0cTelegram\u7684\u6d88\u606f\u662f\u53ef\u4ee5\u7f16\u8f91\u3001\u5220\u9664\u7684\uff0c\u673a\u5668\u4eba\u4e5f\u540c\u6837\u53ef\u4ee5\u505a\u5230\u3002\u5f53\u7136\u4e86\uff0creply_markup\u5176\u5b9e\u4e5f\u53ef\u4ee5\u88ab\u7f16\u8f91\u7684\uff0c\u6211\u4eec\u5c31\u6765\u7b80\u5355\u7684\u505a\u4e00\u4e2a\u793a\u4f8b\u5427\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8bf4\u5230\u7f16\u8f91\u3001\u5220\u9664\u6d88\u606f\uff0c\u6211\u4eec\u53ea\u9700\u8981chat_id\u548cmessage_id\u5c31\u53ef\u4ee5\u4e86\uff0c\u90a3\u4e48\u7f16\u8f91\u3001\u5220\u9664\u5927\u6982\u5c31\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">@bot.message_handler(commands=[&#039;start&#039;])\r\ndef edit_message(message):\r\n    msg_id = bot.send_message(message.chat.id, &#039;\u8fd9\u91cc\u662f\u539f\u59cb\u6d88\u606f&#039;).message_id\r\n    time.sleep(2)\r\n    # The below comment is wrong!!!\r\n    # bot.edit_message_text(&#039;\u66f4\u65b0\u4e86\u8036&#039;, chat_id=message.chat.id, message_id=message.message_id)\r\n    bot.edit_message_text(&#039;\u66f4\u65b0\u4e86\u8036&#039;, message.chat.id, msg_id)\r\n\r\n\r\n@bot.message_handler(commands=[&#039;help&#039;])\r\ndef delete_message(message):\r\n    msg_id = bot.send_message(message.chat.id, &#039;\u8fd9\u91cc\u662f\u8981\u88ab\u5220\u9664\u7684\u6d88\u606f&#039;).message_id\r\n    time.sleep(2)\r\n    bot.delete_message(message.chat.id, msg_id)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u6548\u679c\u5982\u4e0b\u56fe\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"138\" class=\"wp-image-3429\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134469.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5f88\u591a\u4eba\u6700\u5f00\u59cb\u4f1a\u60f3\u5f53\u7136\u7684\u7ed9message_id\u4f20\u9012message_id\u53c2\u6570\uff0c\u5b9e\u9645\u4e0a<strong>\u8fd9\u662f\u9519\u8bef\u7684<\/strong>\uff01\u5982\u679c\u4f60\u8fd9\u4e48\u505a\uff0c\u90a3\u4e48\u4f60\u4f1a\u6536\u5230<strong>Bad Request: message can't be edited<\/strong>\u7684\u5f02\u5e38\u3002\u5b9e\u9645\u4e0a\uff0c\u4f60\u6240\u4f20\u9012\u7684<strong>message\u5b9e\u4f8b\u662f\u7528\u6237\u53d1\u9001\u8fc7\u6765\u7684\u6d88\u606f<\/strong>\uff08\u5305\u62ec\/start \/help\u7b49\u547d\u4ee4\uff09\uff0c\u6240\u4ee5\u83b7\u53d6\u5230\u7684message_id\u5176\u5b9e\u4e5f\u662f\u7528\u6237\u6d88\u606f\u7684id\uff0c\u673a\u5668\u4eba\u600e\u4e48\u53ef\u80fd\u7f16\u8f91\u7528\u6237\u6d88\u606f\u561b\uff01\u6240\u4ee5\u6b63\u786e\u7684\u59ff\u52bf\u662f\u53bb\u627esend_message\u7684\u8fd4\u56de\u503c\uff0c\u901a\u8fc7\u8fd4\u56de\u503c\u5c31\u53ef\u4ee5\u83b7\u53d6\u5230\u673a\u5668\u4eba\u53d1\u9001\u7684message_id\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5f53\u7136\u4e86\uff0c\u53e6\u5916\u4e00\u79cdhack\u53ef\u4ee5\u8fd9\u4e48\u505a\uff0c\u53ea\u8981\u4f60\u786e\u5b9a\u597d\u4f60\u8981\u7f16\u8f91\u7684\u6d88\u606f\u76f8\u5bf9\u4e8e\u7528\u6237\u6d88\u606f\u7684\u504f\u79fb\u91cf\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">bot.edit_message_text(&#039;\u66f4\u65b0\u4e86\u8036&#039;, message.chat.id, message.message_id + 1)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u8fd8\u5269\u4e0b\u4e00\u79cdeditReplyMessageMarkup\uff0c\u8fd9\u662f\u7528\u6765\u66f4\u65b0reply_markup\u7684\uff0c\u5305\u62ecInlineKeyboard\u548cReplyKeyboard\uff0c\u57fa\u672c\u903b\u8f91\u5c31\u662f\u6784\u9020\u65b0\u7684markup\uff0c\u7136\u540e\u8c03\u7528\uff0c\u4ee5InlineKeyboard\u4e3a\u4f8b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">def edit_reply_markup(message):\r\n    markup = types.InlineKeyboardMarkup()\r\n    btn1 = types.InlineKeyboardButton(&#039;Apple&#039;, url=&#039;https:\/\/www.apple.com&#039;)\r\n    btn2 = types.InlineKeyboardButton(&#039;Microsoft&#039;, url=&#039;https:\/\/www.microsoft.com&#039;)\r\n    markup.add(btn1, btn2)\r\n    # use hack\r\n    bot.edit_message_reply_markup(message.chat.id, message.message_id - 1, reply_markup=markup)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u91cc\u5f15\u7528\u4e86message_id\u8ba1\u7b97\u504f\u79fb\u91cf\uff0c\u5b9e\u9645\u4e0a\u6211\u4eec\u6709\u4e9b\u65f6\u5019\u4f1a\u5728callbackQuery\u4e2d\u7f16\u8f91InlineKeyboard\uff0c\u6b64\u65f6\u53ef\u4ee5\u5e94\u7528<code>call.message.message_id<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"168\" class=\"wp-image-3430\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134455.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8be6\u7ec6\u7684API\u53ef\u4ee5<a href=\"https:\/\/core.telegram.org\/bots\/api#updating-messages\">\u53c2\u8003\u8fd9\u91cc<\/a><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u683c\u5f0f\u5316\u4e0e\u6b63\u5728\u8f93\u5165\u7684\u7279\u6548<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u60f3\u8ba9\u6d88\u606f\u6709\u52a0\u7c97\u3001\u659c\u4f53\u7b49\u6548\u679c\uff0c\u5176\u5b9e\u8fd9\u662f\u975e\u5e38\u7b80\u5355\u7684\uff0c\u53ea\u9700\u8981\u5728send_message\u65f6\u6307\u5b9aparse_mode\u5373\u53ef\u3002Telegram\u652f\u6301Markdown\u4e0eHTML\u4e24\u79cd\u6a21\u5f0f\uff0c\u5177\u4f53\u7684\u4fe1\u606f\u5c31<a href=\"https:\/\/core.telegram.org\/bots\/api#sendmessage\">\u53c2\u8003\u5b98\u65b9\u6587\u6863<\/a>\u5427\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5982\u679c\u60f3\u52a0\u5165\u201c\u6b63\u5728\u8f93\u5165\u201d\u7684\u7279\u6548\uff0c\u90a3\u5c31\u66f4\u7b80\u5355\u4e86\uff0c\u4f7f\u7528send_action\u5c31\u53ef\u4ee5\u4e86\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">bot.send_chat_action(message.chat.id, &#039;typing&#039;)\r\nbot.send_message(message.chat.id, &#039;\u8fd9\u4e2a\u662f_\u659c\u4f53_\u54e6&#039;, parse_mode=&#039;Markdown&#039;)\r\nbot.send_chat_action(message.chat.id, &#039;record_video&#039;)\r\nbot.send_message(message.chat.id, &quot;`print(&#039;hello world&#039;)`&quot;, parse_mode=&#039;Markdown&#039;)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"252\" height=\"102\" class=\"wp-image-3431\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134580.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u64cd\u4f5c\u6570\u636e\u5e93<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">Python\u652f\u6301\u5f88\u591a\u5f88\u591a\u6570\u636e\u5e93\uff0c\u5bf9\u4e8e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6765\u8bf4\uff0c\u5927\u90e8\u5206\u5e93\u7684\u8bbe\u8ba1\u90fd\u662f\u9075\u5faa<a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0249\/\">PEP 249 Python Database API Specification<\/a>\uff0c\u6240\u4ee5\u54b1\u7684\u4f7f\u7528\u5f80\u5f80\u5c31\u662f\u786e\u5b9a\u7528\u54ea\u79cd\u5e93\uff0c\u66f4\u6539\u8fde\u63a5\u5b57\u7b26\u4e32\uff0c\u5176\u4ed6\u7684\u57fa\u672c\u4e0d\u7528\u6539\u53d8\u592a\u591a\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Python\u5185\u5efasqlite\u7684\u652f\u6301\uff0c\u6240\u4ee5\u5728\u673a\u5668\u4eba\u8fd9\u7c7b\u5e94\u7528\u4e2d\uff0c\u7528sqlite\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">sqlite\u7684\u4f7f\u7528\u65b9\u6cd5\u4e5f\u5f88\u7b80\u5355\uff0c\u57fa\u672c\u9075\u5faa\u5982\u4e0b\u6b65\u9aa4\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">import sqlite3\r\n# \u4f7f\u7528\u5185\u5b58\u578b\u6570\u636e\u5e93\uff0c\u5b9e\u9645\u5e94\u7528\u65f6\u5e94\u8be5\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\r\ncon = sqlite3.connect(&#039;:memory:&#039;)\r\n# \u521b\u5efa\u6e38\u6807\r\ncur = con.cursor()\r\ncreate_table = &#039;&#039;&#039;CREATE TABLE IF NOT EXISTS job(\r\ndate DATETIME,\r\ndone TINYINT)\r\n&#039;&#039;&#039;\r\n# \u6267\u884c\u67e5\u8be2\r\ncur.execute(create_table)\r\n# \u63d0\u4ea4\u4e8b\u52a1\uff0c\u5426\u5219\u4e0d\u4f1a\u5199\u5165\u6570\u636e\u5e93\r\ncon.commit()\r\n# \u5173\u95ed\u8fde\u63a5\r\ncon.close()\r\n<\/pre>\n<h3><span style=\"font-size: 12pt;\">\u9632\u6b62\u6ce8\u5165\u7684\u6b63\u786e\u59ff\u52bf<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u9996\u5148\u9700\u8981\u77e5\u9053\u7684\u662f\uff0c\u62fc\u63a5SQL\u547d\u4ee4\u662f\u4e0d\u53ef\u4ee5\u7684\uff0c\u8fd9\u6837\u5f88\u5bb9\u6613<a href=\"https:\/\/dmesg.app\/school-6.html#title-9\">\u5bfc\u81f4\u6ce8\u5165<\/a>\u3002\uff1aPython\u4e0d\u50cfPHP\u3001Java\u7b49\u5b58\u5728\u540d\u4e3aPreparedStatement\u8fd9\u7c7b\u7528\u6cd5\uff0cPython\u9632\u6b62\u6ce8\u5165\u7684\u65b9\u6cd5\u6bd4\u8f83\u5947\u7279\uff0c\u5f88\u7b80\u5355\uff0c\u7ed9<code>cur.execute()<\/code>\u4f20\u5165\u5360\u4f4d\u7b26\u548c\u53c2\u6570\u5217\u8868\u5c31\u53ef\u4ee5\u4e86\uff0c\u5177\u4f53\u6765\u8bf4\uff08\u5bf9\u4e8esqlite\u800c\u8a00\uff09\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">cursor.execute(&quot;SELECT spam FROM eggs WHERE lumberjack = ?&quot;, (lumberjack,))\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5bf9\u4e8eMySQL\u800c\u8a00\uff0c\u4f7f\u7528%s\u4f5c\u4e3a\u5360\u4f4d\u7b26\uff08\u7ba1\u4ed6\u5565\u7c7b\u578b\u7684\u6570\u636e\uff0c\u6570\u5b57\u8fd8\u662f\u4ec0\u4e48\u7684\uff0c\u7528%s\u5c31\u5bf9\u4e86\uff09<\/span><\/p>\n<pre class=\"prettyprint linenums\">cursor.execute(&quot;SELECT spam FROM eggs WHERE lumberjack = %s&quot;, (lumberjack,))\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003<a href=\"https:\/\/stackoverflow.com\/questions\/7929364\/python-best-practice-and-securest-to-connect-to-mysql-and-execute-queries\">StackOverflow: Python best practice and securest to connect to MySQL and execute queries<\/a><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u96c6\u6210requests\u5e93\u5e76\u89e3\u6790json<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">Requests \u552f\u4e00\u7684\u4e00\u4e2a\u975e\u8f6c\u57fa\u56e0\u7684 Python HTTP \u5e93\uff0c\u4eba\u7c7b\u53ef\u4ee5\u5b89\u5168\u4eab\u7528\u3002<\/span><\/p>\n<div id=\"sc_error\"><span style=\"font-size: 12pt;\">\u8b66\u544a\uff1a\u975e\u4e13\u4e1a\u4f7f\u7528\u5176\u4ed6 HTTP \u5e93\u4f1a\u5bfc\u81f4\u5371\u9669\u7684\u526f\u4f5c\u7528\uff0c\u5305\u62ec\uff1a\u5b89\u5168\u7f3a\u9677\u75c7\u3001\u5197\u4f59\u4ee3\u7801\u75c7\u3001\u91cd\u65b0\u53d1\u660e\u8f6e\u5b50\u75c7\u3001\u5543\u6587\u6863\u75c7\u3001\u6291\u90c1\u3001\u5934\u75bc\u3001\u751a\u81f3\u6b7b\u4ea1\u3002<\/span><\/div>\n<p><span style=\"font-size: 12pt;\">\u73b0\u5982\u4eca<a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E5%85%B7%E8%B1%A1%E7%8A%B6%E6%80%81%E4%BC%A0%E8%BE%93\">REST API<\/a>\u975e\u5e38\u6d41\u884c\u3002REST API\u8bf4\u767d\u4e86\u5c31\u662f\u4f7f\u7528\u5404\u79cdHTTP\u8bf7\u6c42\uff08GET\uff0cPOST\uff0cPUT\u554a\u4ec0\u4e48\u7684\uff09\uff0c\u8fd4\u56de\u67d0\u79cd\u8d44\u6e90\uff08\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u662fjson\uff09\uff0c\u6240\u4ee5\u7528requests\u662f\u975e\u5e38\u597d\u7684\u9009\u62e9\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u800c<a href=\"https:\/\/zh.wikipedia.org\/wiki\/JSON\">json<\/a>\u683c\u5f0f\u4e0ePython\u7684\u5b57\u5178\u57fa\u672c\u76f8\u540c\uff0c\u7b80\u76f4\u662f\u4e0d\u8981\u592a\u65b9\u4fbf\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">requests\u7684\u4f7f\u7528\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u5dee\u4e0d\u591a\u5c31\u662f\u4e09\u884c\u4ee3\u7801\u7684\u4e8b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">import requests\r\nr = requests.get(&#039;https:\/\/www.google.com\/ncr&#039;)\r\nprint r.text\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5982\u679c\u9700\u8981POST\u65b9\u6cd5\uff0c\u5c31\u628aget\u6362\u6210post\uff0c\u5982\u679c\u9700\u8981\u66f4\u6539headers\u7b49\uff0c\u5c31\u5199\u4f5c<code>r = requests.get('https:\/\/www.google.com\/ncr', headers={'User-Agent': 'Mozilla', })<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u66f4\u591a\u7684\u9ad8\u7ea7\u7528\u6cd5\u8fd8\u662f\u53c2\u8003<a href=\"http:\/\/docs.python-requests.org\/zh_CN\/latest\/index.html\">requests\u7684\u5b98\u65b9\u624b\u518c<\/a>\u5427<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0d\u5982\u8bd5\u8bd5\u63a5\u5165\u6dd8\u5b9dIP\u5e93\uff0c\u5b9e\u73b0\u4e00\u4e2a\u67e5IP\u5730\u5740\u7684\u673a\u5668\u4eba\u5427\uff1f\uff08\u5f53\u7136\u4e86\uff0c\u8fd9\u53ea\u662f\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff0c\u5176\u5b9e\u8fd8\u662f\u6709\u4e9bbug\u7684\u5566\u2026\u2026\uff09<\/span><\/p>\n<pre class=\"prettyprint\" >@bot.message_handler(commands=['start'])\r\ndef edit_message(message):\r\n    if len(message.text.split(' ')) != 2:\r\n        bot.send_chat_action(message.chat.id, 'typing')\r\n        bot.send_message(message.chat.id, '\u53c2\u6570\u9519\u8bef')\r\n    else:\r\n        location = get_location(message.text.split(' ')[1])\r\n        bot.send_chat_action(message.chat.id, 'typing')\r\n        bot.send_message(message.chat.id, u\"\u4f60\u67e5\u8be2\u7684IP\u5730\u5740\uff1a`%s`\\n%s\" % (message.text.split(' ')[1], location),parse_mode='Markdown')\r\n\r\n\r\ndef get_location(ip):\r\n    r = requests.get('http:\/\/ip.taobao.com\/service\/getIpInfo.php?ip=' + ip).text\r\n    res = json.loads(r)\r\n    if res.get('code') == 0:\r\n        return res.get('data').get('region') + res.get('data').get('country') + res.get('data').get('isp')\r\n    else:\r\n        return '\u8bf7\u6c42\u5931\u8d25'\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"107\" class=\"wp-image-3432\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/02\/2018020105134576.png\" alt=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" title=\"[Telegram bot \u7cfb\u5217]1\uff1arequests\u5e93\u3001Inline Keyboard\u3001Reply Keyboard\u4e0e\u5176\u4ed6\u7ec6\u8282\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5927\u6982\u5c31\u662f\u8fd9\u4e48\u51e0\u884c\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4eca\u5929\u7684\u6559\u7a0b\u5c31\u5230\u8fd9\u91cc\u4e86\u3002\u672c\u7bc7\u6587\u7ae0\u6d89\u53ca\u5230\u7684\u4ee3\u7801\u53ef\u4ee5\u5728\u8fd9\u91cc\u83b7\u53d6\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><a class=\"dl\" href=\"https:\/\/github.com\/BennyThink\/tools\/tree\/master\/tgbot<\/span>\" target=\"_blank\" rel=\"nofollow\"><i class=\"fa fa-github-alt\"><\/i>\u5f00\u6e90\u5730\u5740<\/a><\/p>\n<h2><span style=\"font-size: 12pt;\">\u6700\u540e<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u8bf4\u592a\u591a\u4e5f\u96be\u4ee5\u8868\u8fbe\u6211\u7684\u5fc3\u60c5\uff0c\u53ef\u80fd\u5df2\u7ecf\u5f7b\u5e95\u5931\u53bb\u5e0c\u671b\u4e86\u5427\u3002<\/span><\/p>\n<blockquote><p><span style=\"font-size: 12pt;\">\u6881\u60e0\u738b\u66f0\uff1a\u201c\u5be1\u4eba\u4e4b\u4e8e\u56fd\u4e5f\uff0c\u5c3d\u5fc3\u7109\u8033\u77e3\u3002\u6cb3\u5185\u51f6\uff0c\u5219\u79fb\u5176\u6c11\u4e8e\u6cb3\u4e1c\uff0c\u79fb\u5176\u7c9f\u4e8e\u6cb3\u5185\u3002\u6cb3\u4e1c\u51f6\u4ea6\u7136\u3002\u5bdf\u90bb\u56fd\u4e4b\u653f\uff0c\u65e0\u5982\u5be1\u4eba\u4e4b\u7528\u5fc3\u8005\u3002\u90bb\u56fd\u4e4b\u6c11\u4e0d\u52a0\u5c11\uff0c\u5be1\u4eba\u4e4b\u6c11\u4e0d\u52a0\u591a\uff0c\u4f55\u4e5f\uff1f\u201d<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5b5f\u5b50\u5bf9\u66f0\uff1a\u201c\u738b\u597d\u6218\uff0c\u8bf7\u4ee5\u6218\u55bb\u3002\u586b\u7136\u9f13\u4e4b\uff0c\u5175\u5203\u65e2\u63a5\uff0c\u5f03\u7532\u66f3\u5175\u800c\u8d70\u3002\u6216\u767e\u6b65\u800c\u540e\u6b62\uff0c\u6216\u4e94\u5341\u6b65\u800c\u540e\u6b62\u3002\u4ee5\u4e94\u5341\u6b65\u7b11\u767e\u6b65\uff0c\u5219\u4f55\u5982\uff1f\u201d<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u66f0\uff1a\u201c\u4e0d\u53ef\uff0c\u76f4\u4e0d\u767e\u6b65\u8033\uff0c\u662f\u4ea6\u8d70\u4e5f\u3002\u201d<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u66f0\uff1a\u201c\u738b\u5982\u77e5\u6b64\uff0c\u5219\u65e0\u671b\u6c11\u4e4b\u591a\u4e8e\u90bb\u56fd\u4e5f\u3002\u4e0d\u8fdd\u519c\u65f6\uff0c\u8c37\u4e0d\u53ef\u80dc\u98df\u4e5f\uff1b\u6570\u7f5f\u4e0d\u5165\u6d3f\u6c60\uff0c\u9c7c\u9cd6\u4e0d\u53ef\u80dc\u98df\u4e5f\uff1b\u65a7\u65a4\u4ee5\u65f6\u5165\u5c71\u6797\uff0c\u6750\u6728\u4e0d\u53ef\u80dc\u7528\u4e5f\u3002\u8c37\u4e0e\u9c7c\u9cd6\u4e0d\u53ef\u80dc\u98df\uff0c\u6750\u6728\u4e0d\u53ef\u80dc\u7528\uff0c\u662f\u4f7f\u6c11\u517b\u751f\u4e27\u6b7b\u65e0\u61be\u4e5f\u3002\u517b\u751f\u4e27\u6b7b\u65e0\u61be\uff0c\u738b\u9053\u4e4b\u59cb\u4e5f\u3002\u4e94\u4ea9\u4e4b\u5b85\uff0c\u6811\u4e4b\u4ee5\u6851\uff0c\u4e94\u5341\u8005\u53ef\u4ee5\u8863\u5e1b\u77e3\uff1b\u9e21\u8c5a\u72d7\u5f58\u4e4b\u755c\uff0c\u65e0\u5931\u5176\u65f6\uff0c\u4e03\u5341\u8005\u53ef\u4ee5\u98df\u8089\u77e3\uff1b\u767e\u4ea9\u4e4b\u7530\uff0c\u52ff\u593a\u5176\u65f6\uff0c\u6570\u53e3\u4e4b\u5bb6\u53ef\u4ee5\u65e0\u9965\u77e3\uff1b\u8c28\u5ea0\u5e8f\u4e4b\u6559\uff0c\u7533\u4e4b\u4ee5\u5b5d\u608c\u4e4b\u4e49\uff0c\u9881\u767d\u8005\u4e0d\u8d1f\u6234\u4e8e\u9053\u8def\u77e3\u3002\u4e03\u5341\u8005\u8863\u5e1b\u98df\u8089\uff0c\u9ece\u6c11\u4e0d\u9965\u4e0d\u5bd2\uff0c\u7136\u800c\u4e0d\u738b\u8005\uff0c\u672a\u4e4b\u6709\u4e5f\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u72d7\u5f58\u98df\u4eba\u98df\u800c\u4e0d\u77e5\u68c0\uff0c\u6d82\u6709\u997f\u83a9\u800c\u4e0d\u77e5\u53d1\uff1b<strong>\u4eba\u6b7b\uff0c\u5219\u66f0\uff1a\u2018\u975e\u6211\u4e5f\uff0c\u5c81\u4e5f\u3002\u2019\u662f\u4f55\u5f02\u4e8e\u523a\u4eba\u800c\u6740\u4e4b\uff0c\u66f0\uff1a\u2018\u975e\u6211\u4e5f\uff0c\u5175\u4e5f\u3002\u2019<\/strong>\u738b\u65e0\u7f6a\u5c81\uff0c\u65af\u5929\u4e0b\u4e4b\u6c11\u81f3\u7109\u3002\u201d<\/span><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u5728 2019\u5e7410\u670831\u65e520:06:58 \u66f4\u65b0\u4e86\u54e6~\u53c8\u5230\u4e86\u4e00\u5e74\u4e00\u5ea6\u5199\u201c\u65b0\u5e74\u9996\u535a\u201d\u7684\u65f6\u5019\uff01\u5f88\u9ad8\u5174\uff0c\u672c\u535a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-3415","post","type-post","status-publish","format-standard","hentry","category-program"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/comments?post=3415"}],"version-history":[{"count":0,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3415\/revisions"}],"wp:attachment":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/media?parent=3415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/categories?post=3415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/tags?post=3415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}