微信发送图片消息

This commit is contained in:
Wang Kejun 2023-10-22 12:13:05 +08:00
parent dd60ecd25c
commit 7bce1dc06d
32 changed files with 484 additions and 146 deletions

View File

@ -59,6 +59,7 @@ export async function createSession(params, context) {
},
filter: {
openId: FromUserName,
applicationId: entityId,
},
}, {});
const result = await context.select('session', {
@ -76,28 +77,95 @@ export async function createSession(params, context) {
openId: FromUserName,
},
}, {});
const sessionMessage = {
id: await generateNewIdAsync(),
applicationId: entityId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
aaoe: false,
extra: data,
userId,
};
if (MsgType === 'text') {
Object.assign(sessionMessage, {
text: Content,
});
}
else if (MsgType === 'image') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'image',
tag1: 'image',
objectId: generateNewIdAsync(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
extra2: {
isPermanent: false,
},
},
},
],
});
}
else if (MsgType === 'video') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'video',
tag1: 'video',
objectId: generateNewIdAsync(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
}
else if (MsgType === 'voice') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'audio',
tag1: 'audio',
objectId: generateNewIdAsync(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
}
session = result[0];
sessionMessage$session = [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: wechatUser?.applicationId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
text: Content,
aaoe: false,
},
data: sessionMessage,
},
];
if (MsgType === 'image') {
}
else if (MsgType === 'video') {
}
else if (MsgType === 'voice') {
}
break;
}
default: {

View File

@ -8,6 +8,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
executeText: string;
buttonProps: {};
afterCommit: () => void;
beforeCommit: () => boolean | undefined;
beforeCommit: () => boolean | undefined | Promise<boolean | undefined>;
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export default _default;

View File

@ -9,7 +9,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
type?: ButtonProps['type'];
executeText?: string;
buttonProps?: ButtonProps;
beforeCommit?: () => Promise<boolean> | boolean;
beforeCommit?: () => Promise<boolean | undefined> | boolean | undefined;
afterCommit?: () => void;
}, {
upload: () => Promise<void>;

View File

@ -275,7 +275,6 @@ export default OakComponent({
fileType: type,
size,
extension,
entity: 'sessionMessage',
objectId: generateNewId(),
id: generateNewId(),
uploadState: 'uploading',
@ -283,22 +282,28 @@ export default OakComponent({
extra2: {
isPermanent: false,
},
entity: 'sessionMessage',
entityId: sessionMessageId,
};
await this.features.extraFile2.autoUpload(extraFile, originFileObj);
try {
this.updateItem({
createTime: Date.now(),
type: 'image',
extraFile$entity: [
{
id: generateNewId(),
action: 'create',
data: extraFile,
},
],
// extraFile$entity: [
// {
// id: generateNewId(),
// action: 'create',
// data: extraFile,
// },
// ],
}, sessionMessageId);
this.features.extraFile2.addLocalFile(extraFile?.id, originFileObj);
// this.features.extraFile2.addLocalFile(
// extraFile?.id,
// originFileObj
// );
await this.execute(undefined, false);
this.features.extraFile2.upload(extraFile?.id);
// this.features.extraFile2.upload(extraFile?.id);
this.pageScroll('comment');
this.createItem();
}

View File

@ -15,7 +15,7 @@ export interface Schema extends EntityShape {
type: Type;
text?: Text;
files?: ExtraFile[];
news?: String<128>;
link?: String<128>;
aaoe?: Boolean;
extra?: Object;
}

View File

@ -10,11 +10,11 @@ const entityDesc = {
wechatUser: '微信用户',
createTime: '发送时间',
type: '消息类型',
text: '文内容',
text: '文内容',
files: '文件',
news: '文章',
link: '图文',
aaoe: '作为实体的发起者',
extra: '额外信息',
extra: '额外信息',
},
v: {
type: {

View File

@ -141,11 +141,12 @@ export class ExtraFile2 extends Feature {
}
async autoUpload(extraFile, file) {
const extraFileId = extraFile.id || generateNewId();
const applicationId = extraFile.applicationId || this.application.getApplicationId();
await this.cache.operate('extraFile', {
action: 'create',
data: Object.assign(extraFile, {
id: extraFileId,
applicationId: this.application.getApplicationId(),
applicationId,
}),
id: await generateNewIdAsync(),
});

View File

@ -19,7 +19,7 @@ export type OpSchema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
};
@ -32,7 +32,7 @@ export type Schema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
application: Application.Schema;
@ -60,7 +60,7 @@ type AttrFilter = {
createTime: Q_DateValue;
type: Q_EnumValue<Type>;
text: Q_StringValue;
news: Q_StringValue;
link: Q_StringValue;
aaoe: Q_BooleanValue;
extra: Object;
extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata;
@ -84,7 +84,7 @@ export type Projection = {
createTime?: number;
type?: number;
text?: number;
news?: number;
link?: number;
aaoe?: number;
extra?: number | Object;
extraFile$entity?: ExtraFile.Selection & {
@ -140,7 +140,7 @@ export type SortAttr = {
} | {
text: number;
} | {
news: number;
link: number;
} | {
aaoe: number;
} | {

View File

@ -30,7 +30,7 @@ export const desc = {
text: {
type: "text"
},
news: {
link: {
type: "varchar",
params: {
length: 128

View File

@ -1 +1 @@
{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文字内容", "files": "文件", "news": "文章", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } }
{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文本内容", "files": "文件", "link": "图文", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } }

View File

@ -1,6 +1,7 @@
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { assert } from 'oak-domain/lib/utils/assert';
import { WechatSDK, } from 'oak-external-sdk';
import { extraFileProjection } from '../types/Projection';
const triggers = [
{
name: '当sessionMessage创建时时使其相关session更新lmts',
@ -41,7 +42,35 @@ const triggers = [
const closeRootMode = context.openRootMode();
try {
for (const row of rows) {
const { sessionId, aaoe, type, text } = row;
const { id } = row;
const [currentSessionMessage] = await context.select('sessionMessage', {
data: {
id: 1,
sessionId: 1,
text: 1,
type: 1,
userId: 1,
wechatUserId: 1,
wechatUser: {
id: 1,
openId: 1,
},
applicationId: 1,
createTime: 1,
$$createAt$$: 1,
aaoe: 1,
extraFile$entity: {
$entity: 'extraFile',
data: extraFileProjection,
},
},
filter: {
id,
},
count: 1,
indexFrom: 0,
}, {});
const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage;
if (aaoe) {
const msgType = type;
const [sessionMessage] = await context.select('sessionMessage', {
@ -127,14 +156,19 @@ const triggers = [
});
break;
}
// case 'image' :{
// wechatInstance.sendServeMessage({
// openId: sessionMessage.wechatUser?.openId!,
// type: msgType,
// mediaId: '',
// });
// break;
// }
case 'image': {
const extraFile = extraFile$entity && extraFile$entity[0];
if (extraFile) {
const mediaId = extraFile.extra1;
wechatInstance.sendServeMessage({
openId: sessionMessage.wechatUser
?.openId,
type: msgType,
mediaId,
});
}
break;
}
default: {
assert(false, `消息类型「${msgType}」尚未支持`);
}

View File

@ -62,6 +62,7 @@ async function createSession(params, context) {
},
filter: {
openId: FromUserName,
applicationId: entityId,
},
}, {});
const result = await context.select('session', {
@ -79,28 +80,95 @@ async function createSession(params, context) {
openId: FromUserName,
},
}, {});
const sessionMessage = {
id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: entityId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
aaoe: false,
extra: data,
userId,
};
if (MsgType === 'text') {
Object.assign(sessionMessage, {
text: Content,
});
}
else if (MsgType === 'image') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'create',
data: {
id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: entityId,
origin: 'wechat',
type: 'image',
tag1: 'image',
objectId: (0, uuid_1.generateNewIdAsync)(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
extra2: {
isPermanent: false,
},
},
},
],
});
}
else if (MsgType === 'video') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'create',
data: {
id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: entityId,
origin: 'wechat',
type: 'video',
tag1: 'video',
objectId: (0, uuid_1.generateNewIdAsync)(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
}
else if (MsgType === 'voice') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'create',
data: {
id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: entityId,
origin: 'wechat',
type: 'audio',
tag1: 'audio',
objectId: (0, uuid_1.generateNewIdAsync)(),
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
}
session = result[0];
sessionMessage$session = [
{
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'create',
data: {
id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: wechatUser?.applicationId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
text: Content,
aaoe: false,
},
data: sessionMessage,
},
];
if (MsgType === 'image') {
}
else if (MsgType === 'video') {
}
else if (MsgType === 'voice') {
}
break;
}
default: {

View File

@ -8,6 +8,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
executeText: string;
buttonProps: {};
afterCommit: () => void;
beforeCommit: () => boolean | undefined;
beforeCommit: () => boolean | undefined | Promise<boolean | undefined>;
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export default _default;

View File

@ -9,7 +9,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
type?: ButtonProps['type'];
executeText?: string;
buttonProps?: ButtonProps;
beforeCommit?: () => Promise<boolean> | boolean;
beforeCommit?: () => Promise<boolean | undefined> | boolean | undefined;
afterCommit?: () => void;
}, {
upload: () => Promise<void>;

View File

@ -277,7 +277,6 @@ exports.default = OakComponent({
fileType: type,
size,
extension,
entity: 'sessionMessage',
objectId: (0, uuid_1.generateNewId)(),
id: (0, uuid_1.generateNewId)(),
uploadState: 'uploading',
@ -285,22 +284,28 @@ exports.default = OakComponent({
extra2: {
isPermanent: false,
},
entity: 'sessionMessage',
entityId: sessionMessageId,
};
await this.features.extraFile2.autoUpload(extraFile, originFileObj);
try {
this.updateItem({
createTime: Date.now(),
type: 'image',
extraFile$entity: [
{
id: (0, uuid_1.generateNewId)(),
action: 'create',
data: extraFile,
},
],
// extraFile$entity: [
// {
// id: generateNewId(),
// action: 'create',
// data: extraFile,
// },
// ],
}, sessionMessageId);
this.features.extraFile2.addLocalFile(extraFile?.id, originFileObj);
// this.features.extraFile2.addLocalFile(
// extraFile?.id,
// originFileObj
// );
await this.execute(undefined, false);
this.features.extraFile2.upload(extraFile?.id);
// this.features.extraFile2.upload(extraFile?.id);
this.pageScroll('comment');
this.createItem();
}

View File

@ -15,7 +15,7 @@ export interface Schema extends EntityShape {
type: Type;
text?: Text;
files?: ExtraFile[];
news?: String<128>;
link?: String<128>;
aaoe?: Boolean;
extra?: Object;
}

View File

@ -12,11 +12,11 @@ const entityDesc = {
wechatUser: '微信用户',
createTime: '发送时间',
type: '消息类型',
text: '文内容',
text: '文内容',
files: '文件',
news: '文章',
link: '图文',
aaoe: '作为实体的发起者',
extra: '额外信息',
extra: '额外信息',
},
v: {
type: {

View File

@ -144,11 +144,12 @@ class ExtraFile2 extends oak_frontend_base_1.Feature {
}
async autoUpload(extraFile, file) {
const extraFileId = extraFile.id || (0, oak_domain_1.generateNewId)();
const applicationId = extraFile.applicationId || this.application.getApplicationId();
await this.cache.operate('extraFile', {
action: 'create',
data: Object.assign(extraFile, {
id: extraFileId,
applicationId: this.application.getApplicationId(),
applicationId,
}),
id: await (0, oak_domain_1.generateNewIdAsync)(),
});

View File

@ -19,7 +19,7 @@ export type OpSchema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
};
@ -32,7 +32,7 @@ export type Schema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
application: Application.Schema;
@ -60,7 +60,7 @@ type AttrFilter = {
createTime: Q_DateValue;
type: Q_EnumValue<Type>;
text: Q_StringValue;
news: Q_StringValue;
link: Q_StringValue;
aaoe: Q_BooleanValue;
extra: Object;
extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata;
@ -84,7 +84,7 @@ export type Projection = {
createTime?: number;
type?: number;
text?: number;
news?: number;
link?: number;
aaoe?: number;
extra?: number | Object;
extraFile$entity?: ExtraFile.Selection & {
@ -140,7 +140,7 @@ export type SortAttr = {
} | {
text: number;
} | {
news: number;
link: number;
} | {
aaoe: number;
} | {

View File

@ -33,7 +33,7 @@ exports.desc = {
text: {
type: "text"
},
news: {
link: {
type: "varchar",
params: {
length: 128

View File

@ -1 +1 @@
{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文字内容", "files": "文件", "news": "文章", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } }
{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文本内容", "files": "文件", "link": "图文", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } }

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("oak-domain/lib/utils/uuid");
const assert_1 = require("oak-domain/lib/utils/assert");
const oak_external_sdk_1 = require("oak-external-sdk");
const Projection_1 = require("../types/Projection");
const triggers = [
{
name: '当sessionMessage创建时时使其相关session更新lmts',
@ -43,7 +44,35 @@ const triggers = [
const closeRootMode = context.openRootMode();
try {
for (const row of rows) {
const { sessionId, aaoe, type, text } = row;
const { id } = row;
const [currentSessionMessage] = await context.select('sessionMessage', {
data: {
id: 1,
sessionId: 1,
text: 1,
type: 1,
userId: 1,
wechatUserId: 1,
wechatUser: {
id: 1,
openId: 1,
},
applicationId: 1,
createTime: 1,
$$createAt$$: 1,
aaoe: 1,
extraFile$entity: {
$entity: 'extraFile',
data: Projection_1.extraFileProjection,
},
},
filter: {
id,
},
count: 1,
indexFrom: 0,
}, {});
const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage;
if (aaoe) {
const msgType = type;
const [sessionMessage] = await context.select('sessionMessage', {
@ -129,14 +158,19 @@ const triggers = [
});
break;
}
// case 'image' :{
// wechatInstance.sendServeMessage({
// openId: sessionMessage.wechatUser?.openId!,
// type: msgType,
// mediaId: '',
// });
// break;
// }
case 'image': {
const extraFile = extraFile$entity && extraFile$entity[0];
if (extraFile) {
const mediaId = extraFile.extra1;
wechatInstance.sendServeMessage({
openId: sessionMessage.wechatUser
?.openId,
type: msgType,
mediaId,
});
}
break;
}
default: {
(0, assert_1.assert)(false, `消息类型「${msgType}」尚未支持`);
}

View File

@ -97,6 +97,7 @@ export async function createSession<
},
filter: {
openId: FromUserName,
applicationId: entityId,
},
},
{}
@ -120,27 +121,95 @@ export async function createSession<
},
{}
);
const sessionMessage = {
id: await generateNewIdAsync(),
applicationId: entityId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
aaoe: false,
extra: data,
userId,
};
if (MsgType === 'text') {
Object.assign(sessionMessage, {
text: Content,
});
} else if (MsgType === 'image') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'image',
tag1: 'image',
objectId: generateNewIdAsync(), // 这个域用来标识唯一性
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
extra2: {
isPermanent: false,
},
},
},
],
});
} else if (MsgType === 'video') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'video',
tag1: 'video',
objectId: generateNewIdAsync(), // 这个域用来标识唯一性
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
} else if (MsgType === 'voice') {
Object.assign(sessionMessage, {
extraFile$entity: [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: entityId,
origin: 'wechat',
type: 'audio',
tag1: 'audio',
objectId: generateNewIdAsync(), // 这个域用来标识唯一性
sort: 1000,
uploadState: 'success',
extra1: data.MediaId,
},
},
],
});
}
session = result[0];
sessionMessage$session = [
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
applicationId: wechatUser?.applicationId,
wechatUserId: wechatUser?.id,
createTime: Number(CreateTime) * 1000,
type: MsgType,
text: Content,
aaoe: false,
},
data: sessionMessage,
},
];
if (MsgType === 'image') {
} else if (MsgType === 'video') {
} else if (MsgType === 'voice') {
}
break;
}
default: {

View File

@ -2,6 +2,7 @@ import assert from 'assert';
import { EntityDict } from '../../../oak-app-domain';
import { FileState } from '../../../features/extraFile2';
export default OakComponent({
formData({ features }) {
const ids: string[] = this.getEfIds();
@ -28,7 +29,7 @@ export default OakComponent({
executeText: '',
buttonProps: {},
afterCommit: () => {},
beforeCommit: (() => true) as () => boolean | undefined,
beforeCommit: (() => true) as () => boolean | undefined | Promise<boolean | undefined>,
},
methods: {
getEfIds() {

View File

@ -16,7 +16,10 @@ export default function render(
type?: ButtonProps['type'];
executeText?: string;
buttonProps?: ButtonProps;
beforeCommit?: () => Promise<boolean> | boolean;
beforeCommit?: () =>
| Promise<boolean | undefined>
| boolean
| undefined;
afterCommit?: () => void;
},
{

View File

@ -317,7 +317,6 @@ export default OakComponent({
fileType: type,
size,
extension,
entity: 'sessionMessage',
objectId: generateNewId(),
id: generateNewId(),
uploadState: 'uploading',
@ -325,29 +324,36 @@ export default OakComponent({
extra2: {
isPermanent: false,
},
entity: 'sessionMessage',
entityId: sessionMessageId,
} as EntityDict['extraFile']['CreateSingle']['data'];
await this.features.extraFile2.autoUpload(
extraFile as EntityDict['extraFile']['OpSchema'],
originFileObj
);
try {
this.updateItem(
{
createTime: Date.now(),
type: 'image',
extraFile$entity: [
{
id: generateNewId(),
action: 'create',
data: extraFile,
},
],
// extraFile$entity: [
// {
// id: generateNewId(),
// action: 'create',
// data: extraFile,
// },
// ],
},
sessionMessageId
);
this.features.extraFile2.addLocalFile(
extraFile?.id,
originFileObj
);
// this.features.extraFile2.addLocalFile(
// extraFile?.id,
// originFileObj
// );
await this.execute(undefined, false);
this.features.extraFile2.upload(extraFile?.id);
// this.features.extraFile2.upload(extraFile?.id);
this.pageScroll('comment');
this.createItem();
} catch (err) {

View File

@ -26,7 +26,7 @@ export interface Schema extends EntityShape {
type: Type;
text?: Text;
files?: ExtraFile[];
news?: String<128>;
link?: String<128>;
aaoe?: Boolean; // as agent of entity
extra?: Object;
};
@ -42,11 +42,11 @@ const entityDesc: EntityDesc<Schema, '', '', {}> = {
wechatUser: '微信用户',
createTime: '发送时间',
type: '消息类型',
text: '文内容',
text: '文内容',
files: '文件',
news: '文章',
link: '图文',
aaoe: '作为实体的发起者',
extra: '额外信息',
extra: '额外信息',
},
v: {
type: {

View File

@ -210,11 +210,13 @@ export class ExtraFile2<
file: File | string
) {
const extraFileId = extraFile.id || generateNewId();
const applicationId =
extraFile.applicationId || this.application.getApplicationId();
await this.cache.operate('extraFile', {
action: 'create',
data: Object.assign(extraFile, {
id: extraFileId,
applicationId: this.application.getApplicationId(),
applicationId,
}),
id: await generateNewIdAsync(),
} as EntityDict['extraFile']['Operation']);

View File

@ -20,7 +20,7 @@ export type OpSchema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
};
@ -33,7 +33,7 @@ export type Schema = EntityShape & {
createTime?: Datetime | null;
type: Type;
text?: Text | null;
news?: String<128> | null;
link?: String<128> | null;
aaoe?: Boolean | null;
extra?: Object | null;
application: Application.Schema;
@ -61,7 +61,7 @@ type AttrFilter = {
createTime: Q_DateValue;
type: Q_EnumValue<Type>;
text: Q_StringValue;
news: Q_StringValue;
link: Q_StringValue;
aaoe: Q_BooleanValue;
extra: Object;
extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata;
@ -85,7 +85,7 @@ export type Projection = {
createTime?: number;
type?: number;
text?: number;
news?: number;
link?: number;
aaoe?: number;
extra?: number | Object;
extraFile$entity?: ExtraFile.Selection & {
@ -141,7 +141,7 @@ export type SortAttr = {
} | {
text: number;
} | {
news: number;
link: number;
} | {
aaoe: number;
} | {

View File

@ -32,7 +32,7 @@ export const desc: StorageDesc<OpSchema> = {
text: {
type: "text"
},
news: {
link: {
type: "varchar",
params: {
length: 128

View File

@ -1 +1 @@
{"name":"消息","attr":{"application":"应用","session":"会话","user":"用户","wechatUser":"微信用户","createTime":"发送时间","type":"消息类型","text":"文字内容","files":"文件","news":"文章","aaoe":"作为实体的发起者","extra":"额外信息"},"v":{"type":{"text":"文字","image":"图片","voice":"音频","video":"视频","link":"图文","location":"位置","event":"事件","miniprogrampage":"小程序"}}}
{"name":"消息","attr":{"application":"应用","session":"会话","user":"用户","wechatUser":"微信用户","createTime":"发送时间","type":"消息类型","text":"文本内容","files":"文件","link":"图文","aaoe":"作为实体的发起者","extra":"额外信息"},"v":{"type":{"text":"文字","image":"图片","voice":"音频","video":"视频","link":"图文","location":"位置","event":"事件","miniprogrampage":"小程序"}}}

View File

@ -11,6 +11,7 @@ import {
WechatMpInstance,
WechatPublicInstance,
} from 'oak-external-sdk';
import { extraFileProjection } from '../types/Projection'
const triggers: Trigger<
EntityDict,
@ -69,7 +70,41 @@ const triggers: Trigger<
const closeRootMode = context.openRootMode();
try {
for (const row of rows) {
const { sessionId, aaoe, type, text } = row;
const { id } = row;
const [currentSessionMessage] = await context.select(
'sessionMessage',
{
data: {
id: 1,
sessionId: 1,
text: 1,
type: 1,
userId: 1,
wechatUserId: 1,
wechatUser: {
id: 1,
openId: 1,
},
applicationId: 1,
createTime: 1,
$$createAt$$: 1,
aaoe: 1,
extraFile$entity: {
$entity: 'extraFile',
data: extraFileProjection,
},
},
filter: {
id,
},
count: 1,
indexFrom: 0,
},
{}
);
const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage;
if (aaoe) {
const msgType = type;
@ -184,14 +219,20 @@ const triggers: Trigger<
});
break;
}
// case 'image' :{
// wechatInstance.sendServeMessage({
// openId: sessionMessage.wechatUser?.openId!,
// type: msgType,
// mediaId: '',
// });
// break;
// }
case 'image': {
const extraFile = extraFile$entity && extraFile$entity[0];
if (extraFile) {
const mediaId = extraFile.extra1!;
wechatInstance.sendServeMessage({
openId: sessionMessage.wechatUser
?.openId!,
type: msgType,
mediaId,
});
}
break;
}
default: {
assert(
false,