Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,17 @@ A `TockTheme` can be used as a value of a `ThemeProvider` of [`emotion-theming`]
The main source of configuration for the chatbot interface.
Objects implementing this interface can be passed to `renderChat` or to `TockContext`.

| Property name | Type | Description |
|----------------|-------------------------|------------------------------------------------------|
| `locale` | `string?` | Optional user language, as an *RFC 5646* code |
| `localStorage` | `LocalStorageSettings?` | Configuration for use of localStorage by the library |
| `network` | `NetworkSettings?` | If `true`, disables any SSE connection attempt |
| `renderers` | `RendererSettings?` | Configuration for custom image and text renderers |
| Property name | Type | Description |
|----------------|-------------------------|-----------------------------------------------------------------------------------------------------------------------|
| `endpoint` | `string` | The URL of the web connector endpoint |
| `userId` | `(string\|null)?` | Unique user ID. `null` means no clientside ID. `undefined` (default) generates and stores a UUID in the localStorage. |
| `locale` | `string?` | Optional user language, as an *RFC 5646* code |
| `localStorage` | `LocalStorageSettings?` | Configuration for use of localStorage by the library |
| `network` | `NetworkSettings?` | If `true`, disables any SSE connection attempt |
| `renderers` | `RendererSettings?` | Configuration for custom image and text renderers |

> Note: disabling clientside ID is more secure, but requires setting a different [Web Security Mode](https://github.com/theopenconversationkit/tock/tree/master/bot/connector-web#web-security-modes)
> in the matching bot configuration.

#### `LocalStorageSettings`

Expand Down
5 changes: 4 additions & 1 deletion src/TockContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const TockContext: (props: {
const [state, dispatch] = useReducer(tockReducer, {
quickReplies: [],
messages: [],
userId: retrieveUserId(mergedSettings.localStorage.prefix),
userId:
mergedSettings.userId === undefined
? retrieveUserId(mergedSettings.localStorage.prefix)
: mergedSettings.userId,
loading: false,
sseInitializing: false,
metadata: {},
Expand Down
2 changes: 1 addition & 1 deletion src/TockState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useTockDispatch: () => Dispatch<TockAction> = () => {
export interface TockState {
quickReplies: QuickReply[];
messages: Message[];
userId: string;
userId: string | null;
loading: boolean;
sseInitializing: boolean;
metadata: Record<string, string>;
Expand Down
4 changes: 2 additions & 2 deletions src/network/TockEventSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class TockEventSource {
* @returns a promise that gets resolved when the connection is open
* and gets rejected if the connection fails or this event source is closed
*/
open(endpoint: string, userId: string): Promise<void> {
const url = `${endpoint}/sse?userid=${userId}`;
open(endpoint: string, userId: string | null): Promise<void> {
const url = `${endpoint}/sse${userId == null ? '' : `?userid=${userId}`}`;
this.onStateChange(EventSource.CONNECTING);
this.currentUrl = url;
return new Promise<void>((resolve, reject): void => {
Expand Down
1 change: 1 addition & 0 deletions src/settings/TockSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface NetworkSettings {

export default interface TockSettings {
endpoint?: string; // will be required in a future release
userId?: string | null;
locale?: string;
localStorage: LocalStorageSettings;
network: NetworkSettings;
Expand Down