From 57b7458bd0d5ba57ad8b5a5affd4944a8272e667 Mon Sep 17 00:00:00 2001 From: Naser Mohd Baig Date: Tue, 15 Mar 2022 23:13:35 +0530 Subject: [PATCH] v2.0.1 --- index.d.ts | 40 ++++++++++++++++++++++---------- package.json | 2 +- src/ReactBot.tsx | 2 +- src/coreComponents/Container.tsx | 11 ++++++++- src/redux/actions/dispatch.ts | 12 ++-------- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/index.d.ts b/index.d.ts index a251fbd..ef12c2b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,22 +1,38 @@ -// Type definitions for ReactBot v2.0.0 +// Type definitions for ReactBot v2.0.1 // Project: // Definitions by: Naser Baig -import { ElementType } from "react"; +import { ElementType, FunctionComponent } from "react"; -export const ReactBot: ElementType; +export interface InitialResponse { + Component: ElementType; + props: Record; + avatar?: boolean; +} + +export interface MainProps { + botId?: string; + className?: string; + customLauncherIcon?: string | boolean; + title?: string; + messagePlaceHolder?: string; + autofocus?: boolean; + initialResponse?: InitialResponse | boolean; + typingGif?: string; + titleAvatar?: string; + chatAvatar?: string; + handleUserInput: ( + input: string, + displayTypingEffect: () => void, + hideTypingEffect: () => void + ) => void; +} + +export const ReactBot: FunctionComponent; export function addUserMessage(message: string, botId?: string): Promise; export function addBotMessage(message: string, botId?: string): Promise; export function addCustomComponent( - { - Component, - props, - avatar, - }: { - Component: ElementType; - props: Record; - avatar?: boolean; - }, + { Component, props, avatar }: InitialResponse, botId?: string ): Promise; diff --git a/package.json b/package.json index e929138..fbad56e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cozimacode/react-bot", - "version": "2.0.0", + "version": "2.0.1", "description": "A clean, compact and responsive chat widget for React Apps.", "author": { "name": "Naser Mohd Baig", diff --git a/src/ReactBot.tsx b/src/ReactBot.tsx index 7022948..6574e2d 100644 --- a/src/ReactBot.tsx +++ b/src/ReactBot.tsx @@ -8,7 +8,7 @@ import "./coreComponents/coreStyles/BrowserSpecific.css"; export interface InitialResponse { Component: ElementType; - props: Record; + props: Record; avatar?: boolean; } diff --git a/src/coreComponents/Container.tsx b/src/coreComponents/Container.tsx index 5b77c01..b67b700 100644 --- a/src/coreComponents/Container.tsx +++ b/src/coreComponents/Container.tsx @@ -13,6 +13,7 @@ import { ConversationUI, Conversation } from "./ConversationUI"; import { Header } from "./Header"; import { addUserMessage, + addBotMessage, typingEffect, hideTyping, } from "../redux/actions/dispatch"; @@ -77,7 +78,15 @@ const Inner: FunctionComponent = ({ const handleClick = async () => { await addUserMessage(userInput, botId); - handleUserInput(userInput, displayTypingEffect, hideTypingEffect); + if (typeof handleUserInput === "function") { + handleUserInput(userInput, displayTypingEffect, hideTypingEffect); + } else { + addBotMessage( + `Sorry. Your last message wasn't processed as you probably forgot to supply a valid function as 'handleUserInput' prop to ReactBot.`, + botId + ); + } + setUserInput(""); }; diff --git a/src/redux/actions/dispatch.ts b/src/redux/actions/dispatch.ts index 221916f..f51a2f6 100644 --- a/src/redux/actions/dispatch.ts +++ b/src/redux/actions/dispatch.ts @@ -1,4 +1,4 @@ -import { ElementType } from "react"; +import { InitialResponse } from "../../ReactBot"; import { store } from "../store"; import { InitializeBot, @@ -28,15 +28,7 @@ function addUserMessage(message: string, botId = "default"): Promise { } function addCustomComponent( - { - Component, - props, - avatar = false, - }: { - Component: ElementType; - props: Record; - avatar?: boolean; - }, + { Component, props, avatar = false }: InitialResponse, botId = "default" ): Promise { return new Promise((resolve) => {