@zhin.js/adapter-telegram 1.0.54 → 1.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.56
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4304825: fix: 重新发版
|
|
8
|
+
- Updated dependencies [4304825]
|
|
9
|
+
- @zhin.js/logger@0.1.53
|
|
10
|
+
- @zhin.js/client@1.0.17
|
|
11
|
+
- zhin.js@1.0.71
|
|
12
|
+
- @zhin.js/console@2.0.11
|
|
13
|
+
- @zhin.js/http@1.0.64
|
|
14
|
+
|
|
15
|
+
## 1.0.55
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- zhin.js@1.0.68
|
|
20
|
+
- @zhin.js/logger@0.1.52
|
|
21
|
+
- @zhin.js/console@2.0.10
|
|
22
|
+
- @zhin.js/http@1.0.63
|
|
23
|
+
|
|
3
24
|
## 1.0.54
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addPage as e}from"@zhin.js/client";import{BarChart3 as t,Link2 as n,Loader2 as r,Plus as i,Power as a,PowerOff as o,RefreshCw as s,Send as c,Server as l,ShieldCheck as ee,Wifi as u,WifiOff as d,X as f}from"lucide-react";import{useCallback as p,useEffect as m,useState as h}from"react";import{Fragment as g,jsx as _,jsxs as v}from"react/jsx-runtime";var y="zhin_api_token";function b(){return localStorage.getItem(y)}async function x(e2,t2){let n2=b(),r2=new Headers(t2?.headers);n2&&r2.set("Authorization",`Bearer ${n2}`);let i2=await fetch(e2,{...t2,headers:r2});return i2.status===401&&(localStorage.removeItem(y),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),i2}function S(){let[e2,c2]=h([]),[y2,b2]=h(true),[S2,C]=h(""),[w,T]=h("overview"),[E,D]=h({}),[O,k]=h(""),[A,j]=h(""),[M,N]=h(""),[P,F]=h([]),[I,L]=h(false),[R,z]=h(""),[B,V]=h(["",""]),[H,U]=h(true),[W,G]=h(false),[K,q]=h(""),[J,Y]=h(false),X=p(async()=>{b2(true),C("");try{let e3=await(await x("/api/telegram/bots")).json();e3.success?c2(e3.data):C(e3.error||"获取数据失败")}catch{C("无法连接服务器")}finally{b2(false)}},[]);m(()=>{X()},[X]);let Z=async(e3,t2)=>{D(t3=>({...t3,[e3]:true}));try{let n2=
|
|
1
|
+
import{addPage as e}from"@zhin.js/client";import{BarChart3 as t,Link2 as n,Loader2 as r,Plus as i,Power as a,PowerOff as o,RefreshCw as s,Send as c,Server as l,ShieldCheck as ee,Wifi as u,WifiOff as d,X as f}from"lucide-react";import{useCallback as p,useEffect as m,useState as h}from"react";import{Fragment as g,jsx as _,jsxs as v}from"react/jsx-runtime";var y="zhin_api_token";function b(){return localStorage.getItem(y)}async function x(e2,t2){let n2=b(),r2=new Headers(t2?.headers);n2&&r2.set("Authorization",`Bearer ${n2}`);let i2=await fetch(e2,{...t2,headers:r2});return i2.status===401&&(localStorage.removeItem(y),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),i2}function S(){let[e2,c2]=h([]),[y2,b2]=h(true),[S2,C]=h(""),[w,T]=h("overview"),[E,D]=h({}),[O,k]=h(""),[A,j]=h(""),[M,N]=h(""),[P,F]=h([]),[I,L]=h(false),[R,z]=h(""),[B,V]=h(["",""]),[H,U]=h(true),[W,G]=h(false),[K,q]=h(""),[J,Y]=h(false),X=p(async()=>{b2(true),C("");try{let e3=await(await x("/api/telegram/bots")).json();e3.success?c2(e3.data):C(e3.error||"获取数据失败")}catch{C("无法连接服务器")}finally{b2(false)}},[]);m(()=>{X()},[X]);let Z=async(e3,t2)=>{D(t3=>({...t3,[e3]:true}));try{let n2=await(await x(`/api/telegram/bots/${encodeURIComponent(e3)}/${t2?"disconnect":"connect"}`,{method:"POST"})).json();n2.success||C(n2.error||"操作失败"),await X()}catch{C("操作失败")}finally{D(t3=>({...t3,[e3]:false}))}},Q=async()=>{if(!(!O||!A)){N("");try{let e3=await(await x(`/api/telegram/bots/${encodeURIComponent(O)}/invite`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:A})})).json();e3.success&&e3.data?.invite_link?N(e3.data.invite_link):C(e3.error||"创建失败")}catch{C("创建邀请链接失败")}}},te=async()=>{if(!(!O||!A)){L(true),F([]);try{let e3=await(await x(`/api/telegram/bots/${encodeURIComponent(O)}/admins?chat_id=${encodeURIComponent(A)}`)).json();e3.success&&Array.isArray(e3.data)?F(e3.data):C(e3.error||"获取管理员失败")}catch{C("获取管理员失败")}finally{L(false)}}},ne=async()=>{if(!O||!A||!R)return;let e3=B.filter(e4=>e4.trim());if(e3.length<2){C("至少需要 2 个选项");return}Y(true),q("");try{let t2=await(await x(`/api/telegram/bots/${encodeURIComponent(O)}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:A,question:R,options:e3,is_anonymous:H,allows_multiple:W})})).json();t2.success?q(`投票已发送 (ID: ${t2.data?.message_id??"未知"})`):C(t2.error||"发送失败")}catch{C("发送投票失败")}finally{Y(false)}},$=e2.filter(e3=>e3.connected);return v("div",{className:"p-6 max-w-5xl mx-auto",children:[v("div",{className:"flex items-center justify-between mb-6",children:[v("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[_(l,{className:"w-6 h-6"})," Telegram 机器人"]}),v("button",{onClick:X,disabled:y2,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-sky-500 text-white hover:bg-sky-600 disabled:opacity-50 text-sm",children:[_(s,{className:`w-4 h-4 ${y2?"animate-spin":""}`})," 刷新"]})]}),S2&&v("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200 flex items-center justify-between",children:[_("span",{children:S2}),_("button",{onClick:()=>C(""),className:"text-red-400 hover:text-red-600",children:_(f,{className:"w-4 h-4"})})]}),v("div",{className:"flex gap-1 mb-6 border-b",children:[_("button",{onClick:()=>T("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${w==="overview"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"概览"}),_("button",{onClick:()=>T("actions"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${w==="actions"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"快捷操作"})]}),w==="overview"&&v(g,{children:[!y2&&!e2.length&&!S2&&_("div",{className:"text-center text-gray-500 py-12",children:"暂无 Telegram 机器人实例"}),_("div",{className:"grid gap-4 md:grid-cols-2",children:e2.map(e3=>v("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[v("div",{className:"flex items-center justify-between mb-3",children:[_("span",{className:"font-medium text-lg",children:e3.name}),e3.connected?v("span",{className:"flex items-center gap-1 text-green-600 text-sm",children:[_(u,{className:"w-4 h-4"})," 在线"]}):v("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[_(d,{className:"w-4 h-4"})," 离线"]})]}),e3.botInfo&&v("div",{className:"text-sm text-gray-500 mb-2",children:["@",e3.botInfo.username," (",e3.botInfo.firstName,")"]}),_("div",{className:"text-sm text-gray-600 mb-3",children:v("div",{className:"flex justify-between",children:[_("span",{children:"模式"}),_("span",{className:"font-mono",children:e3.mode})]})}),v("button",{onClick:()=>Z(e3.name,e3.connected),disabled:E[e3.name],className:`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${e3.connected?"bg-red-500 hover:bg-red-600":"bg-green-500 hover:bg-green-600"} disabled:opacity-50`,children:[E[e3.name]?_(r,{className:"w-3.5 h-3.5 animate-spin"}):e3.connected?_(o,{className:"w-3.5 h-3.5"}):_(a,{className:"w-3.5 h-3.5"}),e3.connected?"断开":"连接"]})]},e3.name))})]}),w==="actions"&&v("div",{className:"space-y-6",children:[v("div",{className:"flex flex-wrap items-end gap-3",children:[v("div",{children:[_("label",{className:"block text-xs text-gray-500 mb-1",children:"机器人"}),v("select",{value:O,onChange:e3=>k(e3.target.value),className:"border rounded px-2 py-1.5 text-sm min-w-[140px]",children:[_("option",{value:"",children:"--"}),$.map(e3=>_("option",{value:e3.name,children:e3.name},e3.name))]})]}),v("div",{children:[_("label",{className:"block text-xs text-gray-500 mb-1",children:"Chat ID"}),_("input",{value:A,onChange:e3=>j(e3.target.value),placeholder:"-100xxxxxxxxxx",className:"border rounded px-2 py-1.5 text-sm w-[180px]"})]})]}),!$.length&&_("div",{className:"text-center text-gray-500 py-4",children:"暂无在线机器人"}),O&&A&&v("div",{className:"grid gap-4 md:grid-cols-2",children:[v("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[v("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[_(n,{className:"w-4 h-4 text-sky-500"})," 创建邀请链接"]}),_("button",{onClick:Q,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600",children:"生成链接"}),M&&_("div",{className:"mt-2 p-2 bg-gray-50 rounded text-sm break-all",children:_("a",{href:M,target:"_blank",rel:"noreferrer",className:"text-sky-600 hover:underline",children:M})})]}),v("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[v("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[_(ee,{className:"w-4 h-4 text-sky-500"})," 管理员列表"]}),v("button",{onClick:te,disabled:I,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600 disabled:opacity-50 flex items-center gap-1",children:[I&&_(r,{className:"w-3.5 h-3.5 animate-spin"})," 查询"]}),P.length>0&&_("div",{className:"mt-2 space-y-1",children:P.map(e3=>v("div",{className:"flex items-center justify-between text-sm py-1 border-b last:border-0",children:[v("span",{children:[e3.first_name," ",e3.username?`(@${e3.username})`:""]}),_("span",{className:"text-xs text-gray-400",children:e3.status})]},e3.user_id))})]}),v("div",{className:"border rounded-lg p-4 bg-card shadow-sm md:col-span-2",children:[v("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[_(t,{className:"w-4 h-4 text-sky-500"})," 发起投票"]}),v("div",{className:"space-y-2",children:[_("input",{value:R,onChange:e3=>z(e3.target.value),placeholder:"投票问题",className:"border rounded px-2 py-1.5 text-sm w-full"}),B.map((e3,t2)=>v("div",{className:"flex items-center gap-2",children:[_("input",{value:e3,onChange:e4=>{let n2=[...B];n2[t2]=e4.target.value,V(n2)},placeholder:`选项 ${t2+1}`,className:"border rounded px-2 py-1.5 text-sm flex-1"}),B.length>2&&_("button",{onClick:()=>V(B.filter((e4,n2)=>n2!==t2)),className:"text-gray-400 hover:text-red-500",children:_(f,{className:"w-4 h-4"})})]},t2)),v("button",{onClick:()=>V([...B,""]),className:"flex items-center gap-1 text-sm text-sky-500 hover:text-sky-600",children:[_(i,{className:"w-3.5 h-3.5"})," 添加选项"]}),v("div",{className:"flex items-center gap-4 text-sm text-gray-600",children:[v("label",{className:"flex items-center gap-1",children:[_("input",{type:"checkbox",checked:H,onChange:e3=>U(e3.target.checked)})," 匿名"]}),v("label",{className:"flex items-center gap-1",children:[_("input",{type:"checkbox",checked:W,onChange:e3=>G(e3.target.checked)})," 多选"]})]}),v("button",{onClick:ne,disabled:J||!R,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600 disabled:opacity-50 flex items-center gap-1",children:[J&&_(r,{className:"w-3.5 h-3.5 animate-spin"})," 发送投票"]}),K&&_("div",{className:"text-sm text-green-600",children:K})]})]})]})]})]})}e({key:"telegram-management",path:"/telegram",title:"Telegram",icon:_(c,{className:"w-5 h-5"}),element:_(S,{})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-telegram",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"description": "Zhin.js adapter for Telegram",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"@types/react-dom": "^19.2.1",
|
|
41
41
|
"lucide-react": "^0.469.0",
|
|
42
42
|
"typescript": "^6.0.0",
|
|
43
|
-
"
|
|
44
|
-
"zhin.js": "
|
|
43
|
+
"zhin.js": "1.0.71",
|
|
44
|
+
"@zhin.js/console": "2.0.11"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@zhin.js/
|
|
48
|
-
"@zhin.js/
|
|
49
|
-
"@zhin.js/http": "1.0.
|
|
50
|
-
"@zhin.js/logger": "0.1.
|
|
51
|
-
"zhin.js": "1.0.
|
|
47
|
+
"@zhin.js/console": "2.0.11",
|
|
48
|
+
"@zhin.js/client": "1.0.17",
|
|
49
|
+
"@zhin.js/http": "1.0.64",
|
|
50
|
+
"@zhin.js/logger": "0.1.53",
|
|
51
|
+
"zhin.js": "1.0.71"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@zhin.js/client": {
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 凉菜
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|