Skip to content

Commit 0220f73

Browse files
authored
Merge pull request #24 from atorber/hi
Hi
2 parents 547fdfc + 2124a8a commit 0220f73

23 files changed

Lines changed: 2638 additions & 34 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ file/*
7171
msgStore.json
7272
msgStore-wxbot.json
7373
tests/test2.js
74+
.docs/*

examples/raw-bridge-hi.ts

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/* eslint-disable no-console */
2+
import {
3+
Bridge,
4+
} from '../src/agents/hi/hi-bot.js'
5+
import * as os from 'os'
6+
7+
const rootPath = os.userInfo().homedir
8+
console.log('rootPath:', rootPath)
9+
10+
async function main () {
11+
console.info('Hi Bridge starting...')
12+
const bridge = new Bridge({
13+
apiBaseUrl: process.env['HI_API_BASE_URL'] || '',
14+
appKey: process.env['HI_APP_KEY'] || '',
15+
appSecret: process.env['HI_APP_SECRET'] || '',
16+
selfId: process.env['HI_SELF_ID'] || '',
17+
selfName: process.env['HI_SELF_NAME'] || '',
18+
})
19+
20+
// bridge.on('heartbeat', (message) => {
21+
// console.log('heartbeat:', message)
22+
// });
23+
24+
bridge.on('message', (message) => {
25+
console.log('onmessage:', message)
26+
})
27+
28+
console.info('Hi Bridge started.')
29+
30+
const isLoggedIn = false
31+
console.log('isLoggedIn:', isLoggedIn)
32+
// const roomList: {
33+
// [key:string]:ContactRaw
34+
// } = {}
35+
36+
bridge.on('ready', () => {
37+
console.log('ready...')
38+
39+
// ws.send(destroy_all());
40+
// 获取群成员昵称 success
41+
// bridge.ws.send(bridge.get_chat_nick_p("atorber", "21341182572@chatroom"));
42+
43+
// 获取chatroom 成员昵称
44+
// const payload = bridge.get_chat_nick('21341182572@chatroom')
45+
// console.log('get_chat_nick_res:', payload)
46+
// bridge.ws.send(payload);
47+
48+
// 获取微信个人信息 fail
49+
// const payload = bridge.getPersonalInfo()
50+
// console.log('getPersonalInfo_res:', payload)
51+
// bridge.ws.send(payload);
52+
53+
// 获取群好友信息 fail
54+
// const payload = bridge.get_personal_detail('atorber')
55+
// console.log('get_personal_detail_res:', payload)
56+
// bridge.ws.send(payload);
57+
58+
/** debugview调试信息开关,默认为关
59+
* ws.send(debug_switch());
60+
*/
61+
62+
// 获取群好友列表 success
63+
// bridge.ws.send(bridge.get_chatroom_memberlist());
64+
})
65+
66+
// const contactsRes = await bridge.getContactList()
67+
// console.log('getContactList:', JSON.stringify(contactsRes, undefined, 2))
68+
69+
// for (const contact of contacts) {
70+
// // console.log('contact:', JSON.stringify(contact))
71+
// if (contact.wxid.indexOf('@chatroom') > -1) {
72+
// console.log('room:', contact.name)
73+
// roomList[contact.wxid] = contact
74+
// } else {
75+
// console.log('contact:', contact.name, contact.wxid, contact.node)
76+
// }
77+
// }
78+
79+
// for (const key in roomList) {
80+
// const room = roomList[key]
81+
// const roomid = room?.wxid
82+
// const roomName = room?.name
83+
84+
// const roomNew = await bridge.getRoomList(roomid as string)
85+
// console.log('getRoomList_res:', roomNew)
86+
87+
// const roomMembers = roomNew?.member || {}
88+
// const count = Object.keys(roomMembers).length
89+
// if (count) {
90+
// console.log('roomid:', roomid, 'roomName', roomName, 'roomMembers:', count)
91+
// for (const key in roomMembers) {
92+
// const roomMember = roomMembers[key]
93+
// console.log('roomMember:', roomMember?.NickName, roomMember?.UserName)
94+
// }
95+
// }
96+
// }
97+
98+
// // 发送文本消息
99+
// const messageSendText = await bridge.messageSendText('ledongmao', 'Bridge is ready!')
100+
// console.log('messageSendText_res:', messageSendText.id, messageSendText.status, messageSendText.content, messageSendText.time, messageSendText.type, messageSendText.sender, messageSendText.receiver)
101+
102+
// // 发送@消息
103+
// const messageSendTextAt = await bridge.messageSendTextAt('21341182572@chatroom', ['ledongmao'], 'Bridge is ready!', ['超哥'])
104+
// console.log('messageSendTextAt:', messageSendTextAt)
105+
106+
// // 发送图片
107+
// const messageSendFile1 = await bridge.messageSendPicture('ledongmao', rootPath + '\\Documents\\GitHub\\puppet-bridge\\examples\\media\\test.gif')
108+
// console.log('messageSendFile1:', messageSendFile1)
109+
110+
// // 发送视频
111+
// const messageSendFile2 = await bridge.messageSendFile('ledongmao', rootPath + '\\Documents\\GitHub\\puppet-bridge\\examples\\media\\test.mp4')
112+
// console.log('messageSendFile2:', messageSendFile2)
113+
114+
// // 发送文件
115+
// const messageSendFile3 = await bridge.messageSendFile('ledongmao', rootPath + '\\Documents\\GitHub\\puppet-bridge\\examples\\media\\test.txt')
116+
// console.log('messageSendFile3:', messageSendFile3)
117+
118+
// bridge.on('hook', async ({ method, args }) => {
119+
// // console.log(`onhook事件消息:${new Date().toLocaleString()}\n`, method, JSON.stringify(args))
120+
// console.log(`onhook事件消息:${new Date().toLocaleString()}`, method)
121+
// switch (method) {
122+
// case 'recvMsg':
123+
// void onRecvMsg(args)
124+
// break
125+
// case 'checkQRLogin':
126+
// onScan(args)
127+
// break
128+
// case 'loginEvent':{
129+
// if(!isLoggedIn){
130+
// const loginRes = await Bridge.isLoggedIn()
131+
// if(loginRes){
132+
// onLogin()
133+
// }
134+
// }
135+
// break
136+
// }
137+
// case 'agentReady':
138+
// console.log('agentReady...')
139+
// break
140+
// case 'logoutEvent':
141+
// onLogout(args[0] as number)
142+
// break
143+
// default:
144+
// console.info('onHook没有匹配到处理方法:', method, JSON.stringify(args))
145+
// break
146+
// }
147+
148+
// })
149+
150+
// const onLogin = async () => {
151+
// console.info('登陆事件触发')
152+
// console.info(`登陆状态: ${isLoggedIn}`)
153+
// // await Bridge.sendMsg('filehelper', 'Bridge is ready!')
154+
// const contacts = await Bridge.getContact()
155+
// // console.log(`contacts: ${contacts}`)
156+
// const contactsJSON = JSON.parse(contacts)
157+
// console.log('contacts列表:', contactsJSON.length)
158+
159+
// for (const contact of contactsJSON) {
160+
// if(!contact.name) {
161+
// console.info('好友:', JSON.stringify(contact))
162+
// }
163+
// }
164+
165+
// const roomList = await Bridge.getChatroomMemberInfo()
166+
// // console.log(`roomList: ${roomList}`)
167+
// const roomListJSON = JSON.parse(roomList)
168+
// console.log('roomList列表:', roomListJSON.length)
169+
// // for (const room of roomListJSON) {
170+
// // console.info('room:', room)
171+
// // }
172+
// }
173+
174+
// const onLogout = (bySrv: number) => {
175+
// console.info('登出事件触发:', bySrv)
176+
// console.info(`You are logged out${bySrv ? ' because you were kicked by server.' : ''}.`)
177+
// }
178+
179+
// const onScan = (args: any) => {
180+
// const status: number = args[0]
181+
// const qrcodeUrl: string = args[1]
182+
// const wxid: string = args[2]
183+
// const avatarUrl: string = args[3]
184+
// const nickname: string = args[4]
185+
// const phoneType: string = args[5]
186+
// const phoneClientVer: number = args[6]
187+
// const pairWaitTip: string = args[7]
188+
189+
// const json = {
190+
// avatarUrl,
191+
// nickname,
192+
// pairWaitTip,
193+
// phoneClientVer,
194+
// phoneType,
195+
// qrcodeUrl,
196+
// status,
197+
// wxid,
198+
// }
199+
200+
// console.info('onScan', JSON.stringify(json, null, 2))
201+
// }
202+
203+
// const onRecvMsg = async (args: any) => {
204+
// console.info('onRecvMsg事件触发:', JSON.stringify(args))
205+
206+
// if (args instanceof Error) {
207+
// console.error('onRecvMsg: 参数错误 Error', args)
208+
// return
209+
// }
210+
211+
// const toId = String(args[1])
212+
// const text = String(args[2])
213+
// const talkerId = String(args[3])
214+
215+
// // const nickname = await Bridge.GetContactOrChatRoomNickname(talkerId)
216+
// // console.log('发言人昵称:', nickname)
217+
218+
// const talker = await Bridge.getChatroomMemberNickInfo(talkerId,toId)
219+
// console.log('发言人:', talker)
220+
// if (talkerId && text === 'ding') {
221+
// console.info('叮咚测试: ding found, reply dong')
222+
// await Bridge.sendMsg(toId, 'dong')
223+
// // await Bridge.sendAtMsg(toId, 'dong',talkerId)
224+
// }
225+
// }
226+
}
227+
228+
main()
229+
.catch(e => {
230+
console.error('主函数运行失败:', e)
231+
})

examples/ripe-bridge-ttttupup-wxhelper-3091019.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { FileBox } from 'file-box'
1010

1111
import { PuppetBridgeTtttupupWxhelperV3091019 as PuppetBridge } from '../src/mod.js'
12-
import qrcodeTerminal from 'qrcode-terminal'
12+
import * as qrcodeTerminal from 'qrcode-terminal'
1313
import * as fs from 'fs'
1414

1515
// 初始化检查当前文件加下是否存在日志文件info.log,如果不存在则创建
@@ -176,7 +176,7 @@ const onReady = async () => {
176176
const room = await bot.Room.find({ topic:'大师是群主' })
177177
log.info('room:', room)
178178

179-
const contact = await bot.Contact.find({ name:'luyuchao' })
179+
const contact = await bot.Contact.find({ name:'ledongmao' })
180180
log.info('contact', contact)
181181

182182
// if (room && contact) {

examples/ripe-wechaty-3090223.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function onLogin (user: Contact) {
3838

3939
// 发送@好友消息
4040
// const room = await bot.Room.find({topic:'大师是群主'})
41-
// const contact = await bot.Contact.find({name:'luyuchao'})
41+
// const contact = await bot.Contact.find({name:'ledongmao'})
4242
// log.info('room:', room)
4343
// if(room && contact){
4444
// const contacts:Contact[]= [contact]

examples/ripe-wechaty-Devo919-Gewechat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const onReady = async () => {
231231
const room = await bot.Room.find({ topic:'大师是群主' })
232232
log.info('room:', room)
233233

234-
const contact = await bot.Contact.find({ name:'luyuchao' })
234+
const contact = await bot.Contact.find({ name:'ledongmao' })
235235
log.info('contact', contact)
236236

237237
if (contact) {

examples/ripe-wechaty-atorber-fused-3090825.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const onReady = async () => {
176176
const room = await bot.Room.find({ topic:'大师是群主' })
177177
log.info('room:', room)
178178

179-
const contact = await bot.Contact.find({ name:'luyuchao' })
179+
const contact = await bot.Contact.find({ name:'ledongmao' })
180180
log.info('contact', contact)
181181

182182
// if (room && contact) {

0 commit comments

Comments
 (0)