Skip to content

Commit

Permalink
Set timestamp when a message is received (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiTakamiya authored Nov 6, 2024
1 parent 61e9e50 commit df2d1f8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ansible_ai_connect_chatbot/src/useChatbot/useChatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ export const readCookie = (name: string): string | null => {
return null;
};

const getTimestamp = () => {
const date = new Date();
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
};

export const botMessage = (content: string): MessageProps => ({
role: "bot",
content,
name: botName,
avatar:
"https://access.redhat.com/sites/default/files/images/product_icon-red_hat-ansible_automation_platform-rgb_0.png",
timestamp: getTimestamp(),
actions: {
positive: { onClick: () => console.log("Good response") },
negative: { onClick: () => console.log("Bad response") },
Expand Down Expand Up @@ -67,6 +73,7 @@ export const useChatbot = () => {
name: userName,
avatar:
"https://developers.redhat.com/sites/default/files/inline-images/Skill%20development_0.png",
timestamp: getTimestamp(),
referenced_documents: [],
};
setMessages((msgs: ExtendedMessage[]) => [...msgs, userMessage]);
Expand Down

0 comments on commit df2d1f8

Please sign in to comment.