Skip to main content

Context

Get more details about the components of the Widget.

If you want to know how to install the widget in your application follow the next steps.

NxWhatsApp Hook context

Main hook context required to integrate un your root app.

src/NxWhatsApp.tsx
// Import NxWhatsApp context hook
import { NxWhatsApp } from "@nuveraxgroup/widget";

// Tag context
<NxWhatsApp>
<App/>
</NxWhatsApp>

// Props from NxWhatsApp
export interface NxWhatsAppProps {
children: ReactNode;
authDomain?: string;
}
PropertyRequiredDescription
authDomainUse to define the authentication domain. Default value https://wa.nuverax.com/.
childrenReact children component.

WhatsAppWidget component

src/WhatsAppWidget.tsx
// Import WhatsAppWidget component
import {WhatsAppWidget} from "@nuveraxgroup/widget";

// Component tag
<WhatsAppWidget
onAuthResult={
(isAuth: boolean, token: string) => {
// After a success authentication
}
}/>

// Props from WhatsAppWidget
export interface WhatsAppWidgetProps {
appId?: string;
onAuthResult: (isAuth: boolean, token: string) => void;
}
PropertyRequiredDescription
appIdAppication id to start authentication flow (we will load information from this app).
onAuthResultResult event of the authentication. isAuth: true is the authentication was succesful. token: JSON Web Token of the current session.

useNxWhatsAppContext Hook

Handle session state of the user.

src/NxWhatsAppContext.ts
// Import useNxWhatsAppContext hook
import {useNxWhatsAppContext} from "@nuveraxgroup/widget";

// Hook call
const waContext = useNxWhatsAppContext()

// Props from useNxWhatsAppContext
export interface NxWhatsAppContextProps {
getToken: (appId?: string) => Promise<string | null>;
authenticated: boolean;
isAUth: () => Promise<boolean>;
logout: (appId?: string) => Promise<void>;
}
PropertyDescription
getTokenRetrieves the current JSON Web Token of the user session (we already handle refresh tokens, so you always get a valid token).
-appId: Your application id.
authenticatedtrue if the user has an active session. Usefull with useEffect hook.
isAUthRetrieves the current session status. true is the user has an active session.
logoutLogout all the current sessions.
-appId: Your application id, we will redirect to your specific app endpoint after a success logout.