Commit c3b5aba8 authored by nanahira's avatar nanahira

more types

parent a3651f5b
......@@ -30,22 +30,31 @@ app.on('wecom/event', (session) => {
console.log(`Got event ${JSON.stringify(session.wecom)}`);
});
app.on('wecom/message', (session) => {
console.log(`Got custom message ${JSON.stringify(session.wecom)}`);
});
app.on('message', (session) => {
console.log(`Got message ${session.content}`);
});
app
.command('test1')
.command('image')
.action(async () =>
segment.image(await fs.promises.readFile(__dirname + '/10000.jpg')),
);
app.command('markdown').action(async () => {
return `${segment('markdown')}# 女装\n> 今天梦梦女装了吗?`;
});
app
.command('test2')
.action(async () =>
segment.image(
'https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/10000.jpg',
),
.command('media')
.option('type', '-t, <type:string>', { fallback: 'image' })
.action(async (argv) =>
segment(argv.options.type, {
url: 'https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/10000.jpg',
}),
);
app.start();
......@@ -283,7 +283,7 @@ export class WeComBot extends Bot<BotConfig> {
}
async sendMediaMessage(
type: 'image' | 'video',
type: string,
fileName: string,
message: Buffer,
targetUsers: string[],
......@@ -367,6 +367,8 @@ export class WeComBot extends Bot<BotConfig> {
break;
case 'image':
case 'video':
case 'file':
case 'voice':
if (!data.url) {
break;
}
......
......@@ -52,6 +52,13 @@ export interface WecomPicBody extends WecomMediaBody {
PicUrl: string;
}
export interface WecomLinkBody extends WecomEventBody {
Title: string;
Description: string;
Url: string;
PicUrl: string;
}
export interface CardEventSelectedItems {
SelectedItem: CardEventSelectedItem | CardEventSelectedItem[];
}
......
......@@ -3,6 +3,8 @@ import { WeComBot } from './bot';
import {
WecomChatBody,
WecomEventResponse,
WecomLinkBody,
WecomLocationBody,
WecomPicBody,
WecomResponse,
WeComUser,
......@@ -52,12 +54,8 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
if (body.MsgType === 'event') {
session.type = 'wecom/event';
session.subtype = body.Event;
} else if (body.MsgType === 'text' || body.MsgType === 'image') {
session.type = 'message';
session.subtype = 'private';
session.author = {
userId: session.userId,
};
} else {
let isKnownMessage = true;
switch (body.MsgType) {
case 'text':
const textBody = body as WecomChatBody;
......@@ -69,10 +67,22 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
url: imageBody.PicUrl,
});
break;
case 'link':
const linkBody = body as WecomLinkBody;
session.content = linkBody.Url;
default:
isKnownMessage = false;
}
if (isKnownMessage) {
session.type = 'message';
session.subtype = 'private';
session.author = {
userId: session.userId,
};
} else {
session.type = 'wecom/message';
session.subtype = body.MsgType;
}
} else {
session.type = 'wecom/message';
session.subtype = body.MsgType;
}
return session;
}
......
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