From 334029e9f605eb774af8fdc65af11c131be19d80 Mon Sep 17 00:00:00 2001 From: tjtanjin Date: Sun, 6 Oct 2024 02:31:12 +0800 Subject: [PATCH] feat: Add new hook for retrieving bot id --- src/hooks/internal/useBotIdInternal.tsx | 20 ++++++++++++++++++++ src/hooks/useBotId.tsx | 13 +++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/hooks/internal/useBotIdInternal.tsx create mode 100644 src/hooks/useBotId.tsx diff --git a/src/hooks/internal/useBotIdInternal.tsx b/src/hooks/internal/useBotIdInternal.tsx new file mode 100644 index 00000000..bdfcbafd --- /dev/null +++ b/src/hooks/internal/useBotIdInternal.tsx @@ -0,0 +1,20 @@ +import { useBotRefsContext } from "../../context/BotRefsContext"; + +/** + * Internal custom hook for managing bot id. + */ +export const useBotIdInternal = () => { + // handles bot refs + const { botIdRef } = useBotRefsContext(); + + /** + * Retrieves the id for the chatbot. + */ + const getBotId = () => { + return botIdRef.current; + } + + return { + getBotId + }; +} \ No newline at end of file diff --git a/src/hooks/useBotId.tsx b/src/hooks/useBotId.tsx new file mode 100644 index 00000000..7fb4294f --- /dev/null +++ b/src/hooks/useBotId.tsx @@ -0,0 +1,13 @@ +import { useBotIdInternal } from "./internal/useBotIdInternal"; + +/** + * External custom hook for managing bot id. + */ +export const useBotId = () => { + // handles bot id + const { getBotId } = useBotIdInternal(); + + return { + getBotId + }; +} \ No newline at end of file