refactor: 调整开放平台机器人服务消息回调通知

pull/70/head
moonrailgun 2 years ago
parent 9af6a3901e
commit d120772257

@ -73,9 +73,9 @@ export function call(ctx: TcPureContext) {
/**
*
*/
async getUserInfo(userId: string): Promise<UserStruct> {
async getUserInfo(userId: string): Promise<UserStruct | null> {
return await ctx.call('user.getUserInfo', {
userId,
userId: String(userId),
});
},
/**
@ -112,5 +112,22 @@ export function call(ctx: TcPureContext) {
: (userAllPermissions ?? []).includes(p)
);
},
/**
*
* @param type : plugin:com.msgbyte.topic
* @param payload
* @param userId userId
*/
async appendInbox(
type: string,
payload: any,
userId?: string
): Promise<boolean> {
return await ctx.call('chat.inbox.append', {
userId,
type,
payload,
});
},
};
}

@ -48,6 +48,10 @@ class OpenAppService extends TcService {
params: {
appId: 'string',
},
cache: {
keys: ['appId'],
ttl: 60 * 60, // 1 hour
},
});
this.registerAction('create', this.create, {
params: {
@ -204,6 +208,8 @@ class OpenAppService extends TcService {
})
.exec();
await this.cleanAppInfoCache(appId);
return true;
}
@ -241,6 +247,8 @@ class OpenAppService extends TcService {
},
}
);
await this.cleanAppInfoCache(appId);
}
/**
@ -277,6 +285,15 @@ class OpenAppService extends TcService {
},
}
);
await this.cleanAppInfoCache(appId);
}
/**
*
*/
private async cleanAppInfoCache(appId: string) {
await this.cleanActionCache('get', [String(appId)]);
}
}

@ -15,7 +15,11 @@ class OpenBotService extends TcService {
}
this.registerEventListener('chat.inbox.append', async (payload, ctx) => {
const userInfo = await call(ctx).getUserInfo(payload._id);
const userInfo = await call(ctx).getUserInfo(String(payload.userId));
if (!userInfo) {
return;
}
if (userInfo.type !== 'openapiBot') {
return;
@ -44,9 +48,9 @@ class OpenBotService extends TcService {
}
got
.post(callbackUrl)
.then((res) => {
this.logger.info('调用机器人通知接口回调成功', res);
.post(callbackUrl, { json: payload })
.then(() => {
this.logger.info('调用机器人通知接口回调成功');
})
.catch((err) => {
this.logger.error('调用机器人通知接口回调失败:', err);
@ -121,7 +125,7 @@ class OpenBotService extends TcService {
});
try {
const botId = 'open_' + appInfo._id;
const botId = 'open_' + appInfo.appId;
const nickname = appInfo.appName;
const avatar = appInfo.appIcon;
const { _id: botUserId, email } = await ctx.call<

Loading…
Cancel
Save