wechat-chatgpt icon indicating copy to clipboard operation
wechat-chatgpt copied to clipboard

support self-ask in private message

Open Benature opened this issue 2 years ago • 7 comments

我朋友只有一个微信号,他想把自己的微信作为 ChatGPT 机器人使用。在与别人私聊的对话中,他希望自己也可以通过触发关键词来向 ChatGPT 提问。因此做了以下的改动,私以为对于没有多余微信号的使用者还是有点用的。

  • isNonsense 过滤中忽略了 talker 是 self 的情况
  • 如果 talker 是 self 则 say 的对象为 listener。(为了保证类型后面加了 || talker

Benature avatar Dec 11 '22 18:12 Benature

我朋友只有一个微信号,他想把自己的微信作为 ChatGPT 机器人使用。在与别人私聊的对话中,他希望自己也可以通过触发关键词来向 ChatGPT 提问。因此做了以下的改动,私以为对于没有多余微信号的使用者还是有点用的。

  • isNonsense 过滤中忽略了 talker 是 self 的情况
  • 如果 talker 是 self 则 say 的对象为 listener。(为了保证类型后面加了 || talker

Hi @Benature , thank you for your PR After testing, I found that sending a message to myself gives me an uncaughtException AssertionError [ERR_ASSERTION]: 1204 == 0 error. And 100% triggered image Is there something wrong with my operation?

RealTong avatar Dec 12 '22 03:12 RealTong

I've encountered the 发送文本消息失败 only before I modified L373-374. I thought it was because that wechaty say to the bot wechat itself. May I ask how did you test in the wechat sending message? Here is my test (my ChatGPT token failed for now so I just returned a fixed string)

image image
  async onPrivateMessage(talker: ContactInterface, text: string) {
    const talkerId = talker.id;
-    // const gptMessage = await this.getGPTMessage(text, talkerId);
+    const gptMessage = "gpt message";
    await this.trySay(talker, gptMessage);
  }

(The triggered word is 小G)

Benature avatar Dec 12 '22 04:12 Benature

Seems it is about the empty triggered word, I will check it in the afternoon.

Benature avatar Dec 12 '22 04:12 Benature

last commit: In isNonsense, I filter out the private chat that is not sending text, or it will trigger ChatGPT if no trigger word is set.

(talker.self() && messageType != MessageType.Text)

Benature avatar Dec 12 '22 04:12 Benature

如果是自问自答,建议要搭配 CHAT_TRIGGER_RULE 使用。必须要符合规则才触发

chenzn1 avatar Feb 22 '23 04:02 chenzn1

这个MR挺好的,试了下可用。参考这个commit: https://github.com/sundl123/wechat-chatgpt/commit/2120ef461dd4a33c2305bab92b1c80bf8fda974a

sundl123 avatar Mar 13 '23 02:03 sundl123

@Benature @sundl123 这两个方案我都试过了, 还是会出现发送「发送文本信息失败」的错误啊.

RealTong avatar Mar 17 '23 02:03 RealTong