1.5.0 • Published 4 years ago

@snapcall/agent-app-react v1.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

SnapCall Agent App React

The SnapCall Agent App is a react component that will help you integrate SnapCall to receive calls.

This component is using the SnapCall widget API, and need a working react environment like this one.

Installation

npm install @snapcall/agent-app-react

Basic usage

import { AgentApp } from '@snapcall/agent-app-react';

const App = () => (
  <AgentApp apiKey="123" agentEmail="sauveur@snapcall.io" />
);

Props

AgentApp

NameTypeDescription
apiKeystringYour SnapCall API key
agentEmailstringThe email of the agent receiving calls
snapcalljsUrl?stringA custom URL for the SnapCall Widget SDK script
onDisconnect?() => voidEvent triggered when the agent got disconnected
onReconnect?() => voidEvent triggered when the agent got reconnected
onClientLostConnection?() => voidEvent triggered when the client lost connection
onClientWeakNetwork?() => voidEvent triggered when the client network is weak
onAgentMicrophoneDown?() => voidEvent triggered when the agent microphone is down
onAgentMicrophoneUp?() => voidEvent triggered when the agent microphone is up
loadingView?() => ReactNodeView used for loading
waitingView?({ resetWrapUpTime: Function, wrapUpTimeLeft: number, startOutboundCall: Function, VideoPreview: ReactNode }) => ReactNodeView used when the agent is waiting for a call (ready)
ringingView?({ answer: Function, decline: Function, callID: string, VideoPreview: ReactNode }) => ReactNodeView used when the agent is receiving a call
inCallView?({ hangUp: Function, toggleHold: Function, timer: number, Video: ReactNode }) => ReactNodeView used when the agent is in call
errorView?({ error: string }) => ReactNodeView used when a blocking error occurs

Waiting view

Parameters available in the WaitingView component:

NameTypeDescription
resetWrapUpTime() => voidAlias for snapcallAPI.resetWrapUpTime
wrapUpTimeLeftnumberSeconds left until wrap up time is over
startOutboundCall({ phoneNumber: string }) => voidStart an outbound call on the provided phone number

Ringing view

Parameters available in the RingingView component:

NameTypeDescription
answer() => voidFunction to answer the call
decline() => voidFunction to decline the call
callIDstringThe ID of the ringing call

In Call View

Parameters available in the InCallView component:

NameTypeDescription
hangUp() => voidFunction to hang up the call
toggleHold() => voidFunction to put the call on hold or to resume it
timernumberSeconds since the call started
VideoReactNodeSee Video component details below

Video

The Video component is available as a props for the inCallView.

NameTypeDescription
timer?numberIf set, will display the call timer on top of the video element
hideControls?booleanWhether the control buttons should be displayed or not

Example

import { AgentApp } from '@snapcall/agent-app-react';

const RingingView = ({ answer, decline, callID }) => (
  <div>
    <p>A call is coming! (ID: {callID})</p>
    <button onClick={answer}>Answer</button>
    <button onClick={decline}>Decline</button>
  </div>
);

const InCallView = ({ hangUp, timer, Video }) => (
  <div>
    <Video timer={timer} />
    <button onClick={hangUp}>Hang up</button>
  </div>
);

const App = () => (
  <AgentApp
    apiKey="123"
    agentEmail="sauveur@snapcall.io"
    ringingView={RingingView}
    inCallView={InCallView}
    onClientLostConnection={() => console.log('The client lost the connection!!')}
  />
);