Commit c1ea2edb authored by nanahira's avatar nanahira

update behavior of broadcast

parent 00e20f8a
......@@ -339,7 +339,11 @@ export class WeComBot extends Bot<BotConfig> {
return this.sendPrivateMessage(channelId, content);
}
async sendPrivateMessage(userId, content) {
async sendPrivateMessage(
userId: string,
content: string,
extraUsers: string[] = [],
) {
const session = await this.session({
content,
subtype: 'private',
......@@ -347,6 +351,7 @@ export class WeComBot extends Bot<BotConfig> {
channelId: userId,
});
if (!session?.content) return [];
const userIds = [userId, ...extraUsers];
const chain = segment.parse(session.content);
const messageIds: string[] = [];
let isMarkdown = false;
......@@ -361,8 +366,8 @@ export class WeComBot extends Bot<BotConfig> {
const content = data.content.trim();
messageIds.push(
isMarkdown
? await this.sendMarkdownMessage(content, [userId])
: await this.sendTextMessage(content, [userId]),
? await this.sendMarkdownMessage(content, userIds)
: await this.sendTextMessage(content, userIds),
);
break;
case 'image':
......@@ -381,7 +386,7 @@ export class WeComBot extends Bot<BotConfig> {
break;
}
messageIds.push(
await this.sendMediaMessage(type, filename, buffer, [userId]),
await this.sendMediaMessage(type, filename, buffer, userIds),
);
break;
default:
......@@ -396,6 +401,16 @@ export class WeComBot extends Bot<BotConfig> {
return messageIds;
}
async broadcast(
channels: (string | [string, string])[],
content: string,
delay = this.app.options.delay.broadcast,
) {
const userIds = channels.map((c) => (typeof c === 'string' ? c : c[0]));
if (!userIds.length) return [];
return this.sendPrivateMessage(userIds[0], content, userIds.slice(1));
}
async deleteMessage(channelId: string, messageId: string) {
const token = await this.getToken();
if (!token) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment