Skip to content

Commit

Permalink
Merge pull request #548 from hanshino:fix/chat_session
Browse files Browse the repository at this point in the history
Add OpenaiController.recordSession method for conversation logging
  • Loading branch information
hanshino authored Dec 13, 2024
2 parents 7e72cbb + ff0f922 commit 27599ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ async function App(context) {
OrderBased, // 指令分析
CustomerOrderBased, // 自訂指令分析
interactWithBot, // 標記機器人回應
OpenaiController.recordSession, // 記錄對話
Nothing, // 無符合事件
]);
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/controller/application/OpenaiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ exports.naturalLanguageUnderstanding = async function (context, { next }) {
await context.replyText(reponseText);
};

/**
* 只記錄對話
* @param {import("bottender").LineContext} context
*/
exports.recordSession = async function (context, { next }) {
// 只處理文字訊息
if (!context.event.isText) {
return next;
}
const { text } = context.event.message;

// 不處理太長的文字訊息
if (text.length > 100) {
return next;
}

const sourceType = get(context, "event.source.type");
const sourceId = get(context, `event.source.${sourceType}Id`);
const displayName = get(context, "event.source.displayName");

await recordSession(sourceId, `${displayName}:${text}`);
return next;
};

/**
* 紀錄對話
* @param {String} groupId
Expand Down

0 comments on commit 27599ee

Please sign in to comment.