Skip to content

Commit

Permalink
fix(wecom): fix bot.platform
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 24, 2023
1 parent 0323122 commit 354c8d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions adapters/wecom/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ export class WecomBot extends Bot<WecomBot.Config> {
// internal: Internal
refreshTokenTimer: NodeJS.Timeout
logger = new Logger('wecom')

constructor(ctx: Context, config: WecomBot.Config) {
super(ctx, config)
this.selfId = config.agentId
this.platform = 'wecom'
this.http = ctx.http.extend(config)
// this.internal = new Internal(this.http, this)

ctx.plugin(HttpServer, this)
}

// @ts-ignore
stop(): Promise<void> {
async stop() {
clearTimeout(this.refreshTokenTimer)
}

Expand Down Expand Up @@ -129,5 +131,3 @@ export namespace WecomBot {
Quester.createConfig('https://qyapi.weixin.qq.com/'),
])
}

WecomBot.prototype.platform = 'wecom'
5 changes: 1 addition & 4 deletions adapters/wecom/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export class HttpServer extends Adapter.Server<WecomBot> {
}

async start(bot: WecomBot) {
bot.selfId = bot.config.agentId
bot.platform = 'wecom'

await bot.refreshToken()
const self = await bot.getSelf()
bot.avatar = self.avatar
Expand Down Expand Up @@ -48,7 +45,7 @@ export class HttpServer extends Adapter.Server<WecomBot> {
if (data.Encrypt) {
const localSign = getSignature(localBot.config.token, timestamp?.toString(), nonce?.toString(), data.Encrypt)
if (localSign !== msg_signature) return ctx.status = 403
const { message, id } = decrypt(bot.config.aesKey, data.Encrypt)
const { message } = decrypt(bot.config.aesKey, data.Encrypt)
// if (id !== localBot.config.appid) return ctx.status = 403
const { xml: data2 } = await xml2js.parseStringPromise(message, {
explicitArray: false,
Expand Down
1 change: 1 addition & 0 deletions adapters/wecom/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Message } from './types'
import { WecomBot } from './bot'
import { h } from '@satorijs/satori'

export async function decodeMessage(bot: WecomBot, message: Message) {
const session = bot.session()
session.timestamp = message.CreateTime * 1000
Expand Down

0 comments on commit 354c8d5

Please sign in to comment.