Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 313cb6c

Browse files
include sendMessage in useConvoStack hook
1 parent 5f16966 commit 313cb6c

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

‎docs/docs/frontend/use-convostack-hook.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ const updatedContext = {
144144
updateContext("conversation123", updatedContext);
145145
```
146146

147+
### sendMessage
148+
149+
```typescript
150+
sendMessage = async (
151+
message: string,
152+
conversationId: string | null,
153+
agent?: string,
154+
newContext?: {
155+
[key: string]: string;
156+
}
157+
): void
158+
```
159+
160+
Description:
161+
162+
- The `sendMessage` function is used to send messages without using the user input box of the widget or the `ConvoStackEmbed` component.
163+
164+
Parameters:
165+
166+
- `message: string` - The content of the message you want to send.
167+
- `conversationId: string | null` - The ID of the conversation you want to send a message to. To create a new conversation, set this to `null`.
168+
- `agent` - If null, it will use the agent that was set for the existing conversation.
169+
- `newContext: { [key: string]: string }` - The context you want to pass in when sending a message.
170+
147171
### dropSubscription
148172

149173
```typescript
@@ -152,7 +176,7 @@ const dropSubscription = (embedId?: string): void
152176

153177
Description:
154178

155-
- The dropSubscription function is used to drop the WebSocket connection to the subscription of a specific `ConvoStackEmbed` component or the widget itself. This function is handled automatically by the component itself, so explicitly calling this function should be <u>limited or avoided</u> unless there is a specific need.
179+
- The `dropSubscription` function is used to drop the WebSocket connection to the subscription of a specific `ConvoStackEmbed` component or the widget itself. This function is handled automatically by the component itself, so explicitly calling this function should be <u>limited or avoided</u> unless there is a specific need.
156180

157181
Parameters:
158182

‎examples/fe-example-react/src/components/MyComponent.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ const MyComponent: React.FC<MyComponentProps> = ({ text }) => {
1010
isWidgetWindowVisible,
1111
openConversationList,
1212
openConversation,
13+
sendMessage,
14+
activeConversationId,
15+
embedActiveConversationId,
1316
} = useConvoStack();
17+
console.log(activeConversationId);
1418
return (
1519
<div className="flex flex-col">
1620
<p className="text-black">{text}</p>
1721
<button
18-
onClick={() => toggleWidgetWindow(!isWidgetWindowVisible)}
22+
onClick={() =>
23+
sendMessage("THIS IS A TEST", embedActiveConversationId["test"])
24+
}
1925
className="bg-red-500 mb-8"
2026
>
21-
test toggle open/close convostack
27+
SEND MESSAGE
2228
</button>
2329
<button
2430
onClick={() => openConversationList()}

‎examples/fe-example-react/tsconfig.tsbuildinfo‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎packages/convostack-frontend-react/src/hooks/useConvoStack.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
SubscribeConversationEventsDocument,
33
UpdateConversationContextDocument,
4+
SendMessageDocument,
45
} from "@graphql";
56
import { useDispatch, useSelector } from "react-redux";
67
import { createApiClient, createWsClient } from "../api/apiClient";
@@ -181,6 +182,24 @@ const useConvoStack = () => {
181182
dispatch(setContext(context));
182183
};
183184

185+
const sendMessage = async (
186+
message: string,
187+
conversationId: string | null,
188+
agent?: string,
189+
newContext?: {
190+
[key: string]: string;
191+
}
192+
) => {
193+
await createApiClient().request(SendMessageDocument, {
194+
message: {
195+
content: message,
196+
},
197+
conversationId: conversationId || null,
198+
agent: agent || null,
199+
context: newContext || context,
200+
});
201+
};
202+
184203
return {
185204
context,
186205
data,
@@ -195,6 +214,7 @@ const useConvoStack = () => {
195214
openConversationList,
196215
updateContext,
197216
dropSubscription,
217+
sendMessage,
198218
};
199219
};
200220

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /