Skip to content

Commit 9933e8e

Browse files
committed
fix: fixed up repeat conversation
1 parent f0d2b48 commit 9933e8e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/chatgpt.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,37 @@ export function initChatGPT() {
1010
});
1111
}
1212

13-
async function getChatGPTReply(content) {
13+
async function getChatGPTReply(content, contactId) {
1414
const { conversationId, text, id } = await chatGPT.sendMessage(
1515
content,
16-
chatOption
16+
chatOption[contactId]
1717
);
1818
chatOption = {
19-
conversationId,
20-
parentMessageId: id,
19+
[contactId]: {
20+
conversationId,
21+
parentMessageId: id,
22+
},
2123
};
2224
console.log('response: ', conversationId, text);
2325
// response is a markdown-formatted string
2426
return text;
2527
}
2628

2729
export async function replyMessage(contact, content) {
30+
const { id: contactId } = contact;
2831
try {
2932
if (
3033
content.trim().toLocaleLowerCase() === config.resetKey.toLocaleLowerCase()
3134
) {
32-
chatOption = {};
35+
chatOption = {
36+
...chatOption,
37+
[contactId]: {},
38+
};
3339
await contact.say('Previous conversation has been reset.');
3440
return;
3541
}
3642
const message = await retryRequest(
37-
() => getChatGPTReply(content),
43+
() => getChatGPTReply(content, contactId),
3844
config.retryTimes,
3945
500
4046
);

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import config from './config.js';
44
import { replyMessage, initChatGPT } from './chatgpt.js';
55

66
let bot: any = {};
7-
initProjest();
7+
initProject();
88
async function onMessage(msg) {
99
const contact = msg.talker();
1010
const receiver = msg.to();
@@ -82,7 +82,7 @@ async function onFriendShip(friendship) {
8282
}
8383
}
8484

85-
async function initProjest() {
85+
async function initProject() {
8686
try {
8787
await initChatGPT();
8888
bot = WechatyBuilder.build({

0 commit comments

Comments
 (0)