提交 447310e5 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

feat: support contactSelf.qrcode() & say(voice.slk) (#1300 #1301)

上级 d050b58c
......@@ -767,72 +767,6 @@ export class Bridge extends PadchatRpc {
const result = await this.WXHeartBeat()
return result.message
}
// public async WXSetUserRemark(contactId: string, alias: string): Promise<void> {
// await this.padchatRpc.WXSetUserRemark(contactId, alias)
// }
// public async WXSendMsg(to: string, content: string, at = ''): Promise<void> {
// await this.padchatRpc.WXSendMsg(to, content, at)
// return
// }
// public async WXSendImage(to: string, data: string): Promise<void> {
// await this.padchatRpc.WXSendImage(to, data)
// }
// public async WXGetChatRoomMember(id: string): Promise<PadchatRoomMemberPayload> {
// log.verbose('PuppetPadchatBridge', 'WXGetChatRoomMember(%s)', id)
// let lastResult: PadchatRoomMemberPayload
// const result = await Misc.retry(async (retry, attempt) => {
// log.silly('PuppetPadchatBridge', 'WXGetChatRoomMember(%s) retry() attempt=%d', id, attempt)
// try {
// lastResult = await this.padchatRpc.WXGetChatRoomMember(id)
// if (lastResult.member.length <= 0) {
// throw new Error('no room member for room ' + id)
// }
// return lastResult
// } catch (e) {
// return retry(e)
// }
// }).catch(e => {
// log.silly('PuppetPadchatBridge', 'WXGetChatRoomMember(%s) retry() fail: %s', id, e)
// return lastResult
// })
// return result
// }
// public async WXDeleteChatRoomMember(roomId: string, contactId: string): Promise<StandardType> {
// const result = await this.padchatRpc.WXDeleteChatRoomMember(roomId, contactId)
// return result
// }
// public async WXAddChatRoomMember(roomId: string, contactId: string): Promise<number> {
// const result = await this.padchatRpc.WXAddChatRoomMember(roomId, contactId)
// return result
// }
// public async WXSetChatroomName(roomId: string, topic: string): Promise<void> {
// await this.padchatRpc.WXSetChatroomName(roomId, topic)
// return
// }
// public async WXQuitChatRoom(roomId: string): Promise<void> {
// await this.padchatRpc.WXQuitChatRoom(roomId)
// }
// public async WXAddUser(strangerV1: string, strangerV2: string, type: string, verify: string): Promise<void> {
// await this.padchatRpc.WXAddUser(strangerV1, strangerV2, type, verify)
// }
// public async WXSetChatroomAnnouncement(chatroom: string, content: string): Promise<void> {
// await this.padchatRpc.WXSetChatroomAnnouncement(chatroom, content)
// }
// public async WXGetChatroomAnnouncement(chatroom: string): Promise<string> {
// return await this.padchatRpc.WXGetChatroomAnnouncement(chatroom)
// }
}
export default Bridge
......@@ -1284,8 +1284,8 @@ export class PadchatRpc extends EventEmitter {
// 获取用户二维码(自己或者已加入的群)
// user 用户名
// style 是否使用风格化二维码
public async WXGetUserQRCode(user: string, style: string): Promise<any> {
const result = await this.rpcCall('WXGetUserQRCode', user, style)
public async WXGetUserQRCode(user: string, style: number): Promise<any> {
const result = await this.rpcCall('WXGetUserQRCode', user, String(style))
log.silly('PadchatRpc', 'WXGetUserQRCode , stranger,result: %s', JSON.stringify(result))
if (!result || result.status !== 0) {
throw Error('WXGetUserQRCode , stranger,error! canot get result from websocket server')
......@@ -1311,8 +1311,8 @@ export class PadchatRpc extends EventEmitter {
// voice_data 语音数据
// voice_size 语音大小 (应该不需要)
// voice_time 语音时间(毫秒,最大60 * 1000)
public async WXSendVoice(user: string, data: string, time: string): Promise<any> {
const result = await this.rpcCall('WXSendVoice', user, data, time)
public async WXSendVoice(user: string, data: string, time: number): Promise<any> {
const result = await this.rpcCall('WXSendVoice', user, data, String(time))
log.silly('PadchatRpc', 'WXSendVoice , stranger,result: %s', JSON.stringify(result))
if (!result || result.status !== 0) {
throw Error('WXSendVoice , stranger,error! canot get result from websocket server')
......
......@@ -17,7 +17,7 @@
*
*/
// import path from 'path'
import path from 'path'
// import fs from 'fs'
// import cuid from 'cuid'
......@@ -350,8 +350,9 @@ export class PuppetPadchat extends Puppet {
throw new Error('can not set avatar for others')
}
throw new Error('not supported')
// return await this.bridge.WXqr
const base64 = await this.bridge.WXGetUserQRCode(contactId, 0)
const qrcode = await pfHelper.imageBase64ToQrCode(base64)
return qrcode
}
public async contactRawPayload(contactId: string): Promise<PadchatContactPayload> {
......@@ -443,10 +444,24 @@ export class PuppetPadchat extends Puppet {
throw new Error('no id!')
}
const type = file.mimeType || path.extname(file.name)
switch (type) {
case '.slk':
// 发送语音消息(微信silk格式语音)
await this.bridge.WXSendVoice(
id,
await file.toBase64(),
60,
)
break
default:
await this.bridge.WXSendImage(
id,
await file.toBase64(),
)
break
}
}
public async messageForward(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册