Commit c3b5aba8 authored by nanahira's avatar nanahira

more types

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