{"id":7075,"date":"2024-10-14T16:11:22","date_gmt":"2024-10-14T08:11:22","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=7075"},"modified":"2025-03-12T11:29:20","modified_gmt":"2025-03-12T03:29:20","slug":"gpt-telegram-worker","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/gpt-telegram-worker\/","title":{"rendered":"Telegram GPT Worker\uff1a\u90e8\u7f72\u5728Cloudflare Workers\u4e0a\u7684\u591a\u6a21\u578bAI Telegram\u673a\u5668\u4eba"},"content":{"rendered":"<p>GPT-Telegram-Worker \u662f\u4e00\u4e2a\u57fa\u4e8e Cloudflare Workers \u7684\u591a\u6a21\u578b AI Telegram \u673a\u5668\u4eba\uff0c\u652f\u6301 OpenAI\u3001Claude\u3001Azure \u7b49\u591a\u4e2a API\u3002\u8be5\u9879\u76ee\u91c7\u7528 TypeScript \u5f00\u53d1\uff0c\u6a21\u5757\u5316\u8bbe\u8ba1\u4fbf\u4e8e\u6269\u5c55\uff0c\u63d0\u4f9b\u5feb\u901f\u3001\u53ef\u6269\u5c55\u7684\u670d\u52a1\u4f53\u9a8c\u3002\u673a\u5668\u4eba\u5177\u5907\u667a\u80fd\u5bf9\u8bdd\u3001\u56fe\u50cf\u751f\u6210\u3001\u56fe\u50cf\u5206\u6790\u7b49\u529f\u80fd\uff0c\u5e76\u652f\u6301\u591a\u8bed\u8a00\uff0c\u6ee1\u8db3\u591a\u6837\u5316\u9700\u6c42\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-7076\" title=\"GPT-Telegram-Worker\uff1a\u591a\u6a21\u578bAI Telegram\u673a\u5668\u4eba-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/bfc6df416201779.png\" alt=\"GPT-Telegram-Worker\uff1a\u591a\u6a21\u578bAI Telegram\u673a\u5668\u4eba-1\" width=\"894\" height=\"392\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/bfc6df416201779.png 1282w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/bfc6df416201779-300x132.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/bfc6df416201779-1024x449.png 1024w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/10\/bfc6df416201779-768x337.png 768w\" sizes=\"auto, (max-width: 894px) 100vw, 894px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li>\u591a\u6a21\u578b\u652f\u6301\uff1a\u6574\u5408 OpenAI\u3001Google Gemini\u3001Anthropic Claude\u3001Groq \u548c Azure OpenAI \u7b49\u591a\u4e2a AI \u6a21\u578b\u3002<\/li>\n<li>\u667a\u80fd\u5bf9\u8bdd\uff1a\u5177\u5907\u4e0a\u4e0b\u6587\u8bb0\u5fc6\u80fd\u529b\uff0c\u786e\u4fdd\u5bf9\u8bdd\u6d41\u7545\u81ea\u7136\u3002<\/li>\n<li>\u56fe\u50cf\u751f\u6210\uff1a\u652f\u6301\u6587\u5b57\u63cf\u8ff0\u751f\u6210\u56fe\u50cf\uff0c\u91c7\u7528 DALL\u00b7E \u548c Cloudflare <a href=\"https:\/\/www.kdjingpai.com\/ja\/manxuebanflux1chan\/\">Flux<\/a> \u6280\u672f\u3002<\/li>\n<li>\u56fe\u50cf\u5206\u6790\uff1a\u652f\u6301\u7528\u6237\u4e0a\u4f20\u56fe\u7247\u5e76\u8fdb\u884c\u667a\u80fd\u5206\u6790\uff0c\u53ef\u4f7f\u7528 OpenAI \u6216 Google <a href=\"https:\/\/www.kdjingpai.com\/ja\/geminibardgubu\/\">Gemini<\/a> \u6a21\u578b\u3002<\/li>\n<li>\u591a\u8bed\u8a00\u652f\u6301\uff1a\u5185\u5efa i18n \u529f\u80fd\uff0c\u652f\u6301 8 \u79cd\u8bed\u8a00\u3002<\/li>\n<li>\u7528\u6237\u6743\u9650\u7ba1\u7406\uff1a\u901a\u8fc7\u767d\u540d\u5355\u529f\u80fd\u63a7\u5236\u8bbf\u95ee\u6743\u9650\uff0c\u63d0\u5347\u5b89\u5168\u6027\u3002<\/li>\n<li>\u9ad8\u6027\u80fd\u90e8\u7f72\uff1a\u5229\u7528 Cloudflare Workers \u7684\u8fb9\u7f18\u8ba1\u7b97\u80fd\u529b\uff0c\u5b9e\u73b0\u5feb\u901f\u54cd\u5e94\u3002<\/li>\n<li>\u9ad8\u6548\u6570\u636e\u7ba1\u7406\uff1a\u4f7f\u7528 Redis \u8fdb\u884c\u6570\u636e\u7f13\u5b58\u548c\u7ba1\u7406\uff0c\u786e\u4fdd\u9ad8\u6548\u5904\u7406\u3002<\/li>\n<li>Flux \u63d0\u793a\u8bcd\u4f18\u5316\uff1a\u901a\u8fc7\u5916\u90e8 API \u4f18\u5316 Flux \u6a21\u578b\u7684\u56fe\u50cf\u751f\u6210\u63d0\u793a\u8bcd\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u6d41\u7a0b<\/h3>\n<ol>\n<li><strong>\u51c6\u5907\u5de5\u4f5c<\/strong>\uff1a\n<ul>\n<li>Cloudflare \u8d26\u53f7<\/li>\n<li>Telegram \u8d26\u53f7\u548c Bot <a href=\"https:\/\/www.kdjingpai.com\/ja\/tokenization\/\">Token<\/a><\/li>\n<li>Upstash Redis \u6570\u636e\u5e93\uff08\u9700\u5f00\u542f Eviction \u529f\u80fd\uff09<\/li>\n<li>\u81f3\u5c11\u4e00\u4e2a AI \u670d\u52a1\u7684 API \u5bc6\u94a5<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5feb\u901f\u4e0a\u624b<\/strong>\uff1a\n<ul>\n<li>\u514b\u9686\u9879\u76ee\u4ed3\u5e93\uff1a<code>git clone https:\/\/github.com\/snakeying\/GPT-Telegram-Worker.git<\/code><\/li>\n<li>\u914d\u7f6e\u5fc5\u8981\u7684\u73af\u5883\u53d8\u91cf\uff1a\u5728 <code>.env<\/code> \u6587\u4ef6\u4e2d\u8bbe\u7f6e Cloudflare\u3001Telegram \u548c Redis \u7684\u76f8\u5173\u4fe1\u606f\u3002<\/li>\n<li>\u90e8\u7f72\u5230 Cloudflare Workers\uff1a\n<pre><code class=\"language-bash\">npm install -g @cloudflare\/wrangler\r\nwrangler login\r\nwrangler init telegram-bot\r\n<span class=\"hljs-built_in\">cp<\/span> dist\/index.js telegram-bot\/\r\nwrangler publish\r\n<\/code><\/pre>\n<\/li>\n<li>\u8bbe\u7f6e Telegram Webhook\uff1a\n<pre><code class=\"language-bash\">curl -F <span class=\"hljs-string\">\"url=https:\/\/your-worker.your-subdomain.workers.dev\"<\/span> https:\/\/api.telegram.org\/bot&lt;YOUR_BOT_TOKEN&gt;\/setWebhook\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u4f7f\u7528\u8bf4\u660e<\/h3>\n<ol>\n<li><strong>\u542f\u52a8\u673a\u5668\u4eba<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 <code>\/start<\/code> \u547d\u4ee4\u542f\u52a8\u673a\u5668\u4eba\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/language<\/code> \u5207\u6362\u8bed\u8a00\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/switchmodel<\/code> \u5207\u6362 AI \u6a21\u578b\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/new<\/code> \u5f00\u59cb\u65b0\u7684\u5bf9\u8bdd\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/history<\/code> \u83b7\u53d6\u5bf9\u8bdd\u5386\u53f2\u6458\u8981\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/help<\/code> \u83b7\u53d6\u5e2e\u52a9\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u56fe\u50cf\u751f\u6210<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 <code>\/img<\/code> \u547d\u4ee4\u751f\u6210\u56fe\u50cf\uff08DALL-E\uff09\u3002<\/li>\n<li>\u4f7f\u7528 <code>\/flux<\/code> \u547d\u4ee4\u751f\u6210\u56fe\u50cf\uff08Cloudflare Flux\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u56fe\u50cf\u5206\u6790<\/strong>\uff1a\n<ul>\n<li>\u4e0a\u4f20\u56fe\u7247\u540e\uff0c\u673a\u5668\u4eba\u4f1a\u81ea\u52a8\u8fdb\u884c\u667a\u80fd\u5206\u6790\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6743\u9650\u7ba1\u7406<\/strong>\uff1a\n<ul>\n<li>\u901a\u8fc7\u767d\u540d\u5355\u529f\u80fd\u63a7\u5236\u7528\u6237\u8bbf\u95ee\u6743\u9650\uff0c\u786e\u4fdd\u5b89\u5168\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6570\u636e\u7ba1\u7406<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 Redis \u8fdb\u884c\u6570\u636e\u7f13\u5b58\u548c\u7ba1\u7406\uff0c\u786e\u4fdd\u9ad8\u6548\u5904\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u8be6\u7ec6\u64cd\u4f5c\u6d41\u7a0b<\/h3>\n<ol>\n<li><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\n<ul>\n<li>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa <code>.env<\/code> \u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<pre><code>TELEGRAM_BOT_TOKEN=&lt;Your Telegram Bot Token&gt;\r\nCLOUDFLARE_ACCOUNT_ID=&lt;Your Cloudflare Account ID&gt;\r\nREDIS_URL=&lt;Your Redis URL&gt;\r\n<\/code><\/pre>\n<\/li>\n<li>\u786e\u4fdd\u6240\u6709\u53d8\u91cf\u90fd\u5df2\u6b63\u786e\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u90e8\u7f72\u5230 Cloudflare Workers<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 Wrangler CLI \u90e8\u7f72\u9879\u76ee\uff1a\n<pre><code class=\"language-bash\">wrangler publish\r\n<\/code><\/pre>\n<\/li>\n<li>\u5728 Cloudflare Dashboard \u4e2d\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8bbe\u7f6e Telegram Webhook<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 Telegram Bot API \u8bbe\u7f6e Webhook\uff1a\n<pre><code class=\"language-bash\">curl -F <span class=\"hljs-string\">\"url=https:\/\/your-worker.your-subdomain.workers.dev\"<\/span> https:\/\/api.telegram.org\/bot&lt;YOUR_BOT_TOKEN&gt;\/setWebhook\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u4f7f\u7528\u673a\u5668\u4eba<\/strong>\uff1a\n<ul>\n<li>\u542f\u52a8\u673a\u5668\u4eba\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u547d\u4ee4\u4e0e\u673a\u5668\u4eba\u8fdb\u884c\u4ea4\u4e92\uff0c\u751f\u6210\u56fe\u50cf\u3001\u5206\u6790\u56fe\u7247\u3001\u5207\u6362\u8bed\u8a00\u548c\u6a21\u578b\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>GPT-Telegram-Worker \u662f\u4e00\u4e2a\u57fa\u4e8e Cloudflare Workers \u7684\u591a\u6a21\u578b AI Telegram \u673a\u5668\u4eba\uff0c\u652f\u6301 OpenAI\u3001Claude\u3001Azure \u7b49\u591a\u4e2a API\u3002\u8be5\u9879\u76ee\u91c7\u7528 TypeScript \u5f00\u53d1\uff0c\u6a21\u5757\u5316&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230,386],"class_list":["post-7075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu","tag-zhinengtiyingyong"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/7075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/comments?post=7075"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/7075\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media\/61096"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=7075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=7075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=7075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}