@qihoo/tuitui-openclaw-channel 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qihoo/tuitui-openclaw-channel",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "maintainers": [
5
5
  {
6
6
  "name": "huzunjie",
package/src/channel.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  deleteAccountFromConfigSection,
13
13
  buildChannelConfigSchema,
14
14
  } from 'openclaw/plugin-sdk';
15
- import type { TuiTuiInboundMessage } from './types';
15
+ import type { TuiTuiInboundMessage, TuiTuiOutboundDeliverOptions } from './types';
16
16
  import {
17
17
  CHANNEL_ID,
18
18
  CHANNEL_NAME,
@@ -293,7 +293,7 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
293
293
  return { channel: CHANNEL_ID, messageId: `tuitui-page-${Date.now()}`, chatId };
294
294
  },
295
295
 
296
- sendMedia: async ({ cfg, to, payload, mediaUrl, accountId, account }: any) => {
296
+ sendMedia: async ({ cfg, to, mediaUrl, accountId, account }: any) => {
297
297
  account = account || resolveAccount(cfg, accountId);
298
298
  checkAccount(account, 'send media');
299
299
 
@@ -446,16 +446,10 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
446
446
  const groupCfg = account.groups?.[String(groupId)];
447
447
 
448
448
  // @机器人触发策略
449
- let requireMention = true;
450
- if (groupCfg && typeof groupCfg.requireMention === 'boolean') {
451
- requireMention = groupCfg.requireMention;
452
- }
449
+ const requireMention = typeof groupCfg?.requireMention === 'boolean' ? groupCfg.requireMention : true;
453
450
 
454
451
  // 是否需要回复
455
- let shouldReply = true;
456
- if (groupCfg !== undefined && typeof groupCfg.shouldReply === 'boolean') {
457
- shouldReply = groupCfg.shouldReply;
458
- }
452
+ let shouldReply = typeof groupCfg?.shouldReply === 'boolean' ? groupCfg.shouldReply : true;
459
453
 
460
454
  if (!userAccount || !groupId) {
461
455
  log?.info?.(`[${CHANNEL_ID}] Missing user_account or group_id in group_chat event`);
@@ -617,23 +611,11 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
617
611
  log?.error?.(`[${CHANNEL_ID}] TuiTuiRuntime error,未能发送回复。`);
618
612
  return;
619
613
  }
620
- const currentCfg = await apiRuntime.config.loadConfig();
621
614
  await apiRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
622
615
  ctx: msgCtx,
623
- cfg: currentCfg,
616
+ cfg: await apiRuntime.config.loadConfig(),
624
617
  dispatcherOptions: {
625
- deliver: async (payload: {
626
- text?: string;
627
- body?: string;
628
- mediaUrl?: string;
629
- mediaUrls?: string[];
630
- custom?: {
631
- msgtype: string;
632
- tousers?: string[];
633
- togroups?: string[];
634
- [key: string]: any;
635
- };
636
- }) => {
618
+ deliver: async (payload: TuiTuiOutboundDeliverOptions) => {
637
619
 
638
620
  // 如果设置了 suppressReply 标志,则不发送回复
639
621
  if (suppressReply) {
@@ -657,7 +639,7 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
657
639
  // Handle media messages
658
640
  const mediaUrl = payload.mediaUrl || payload.mediaUrls?.[0];
659
641
  if (mediaUrl) {
660
- const at = chatTypeIsGroup ? [msgUname] : [];
642
+ const at = chatTypeIsGroup && userAccount ? [userAccount] : [];
661
643
  await sendMediaMsg(account, chatTarget, chatTypeIsGroup, mediaUrl, 'tuitui.deliver.media', at);
662
644
  }
663
645
  return;
@@ -666,9 +648,9 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
666
648
  const replyText = payload?.text || payload?.body;
667
649
  if (replyText) {
668
650
  // at 使用 userAccount(群聊 @ 用户)
669
- const atList = chatTypeIsGroup && userAccount ? [userAccount] : [];
651
+ const at = chatTypeIsGroup && userAccount ? [userAccount] : [];
670
652
  // 群消息回复时不再使用 reference_msgid 避免并发时引用错乱,依靠 @ 来提醒用户
671
- await sendTextMsg(account, chatTarget, chatTypeIsGroup, replyText, 'tuitui.deliver.text', atList);
653
+ await sendTextMsg(account, chatTarget, chatTypeIsGroup, replyText, 'tuitui.deliver.text', at);
672
654
  }
673
655
  },
674
656
  onReplyStart: () => {
@@ -679,6 +661,7 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
679
661
  });
680
662
 
681
663
  const onErrOrClose = () => {
664
+ if (ws && ws.readyState !== WebSocket.CLOSED) ws.close(); // 关闭超时链接,防止产生多个
682
665
  _setStatus({ running: false, connected: false });
683
666
  _sendMsg = defSendMsg;
684
667
  if (!abortSignal?.aborted) {
package/src/types.ts CHANGED
@@ -115,3 +115,16 @@ export interface TuiTuiGroupEmojiReactionTarget {
115
115
  group?: string;
116
116
  msgid?: string;
117
117
  }
118
+
119
+ export interface TuiTuiOutboundDeliverOptions {
120
+ text?: string;
121
+ body?: string;
122
+ mediaUrl?: string;
123
+ mediaUrls?: string[];
124
+ custom?: {
125
+ msgtype: string;
126
+ tousers?: string[];
127
+ togroups?: string[];
128
+ [key: string]: any;
129
+ };
130
+ }