JustCall SDK

This repository contains the TypeScript code for the JustCall Dialer SDK, which allows integration of JustCall Dialer functionality into web applications.

You need a JustCall account to be able to use the dialer and the following features.

Installation

Install the SDK package using npm, yarn or pnpm:

npm install @justcall/justcall-dialer-sdk

or

yarn add @justcall/justcall-dialer-sdk

or pnpm

pnpm add @justcall/justcall-dialer-sdk

Constructor

To use the JustCall Dialer SDK, you need to create an instance of the JustCallDialer class using its constructor. The constructor accepts an object with the following parameters:

Example:

import { JustCallDialer } from "@justcall/justcall-dialer-sdk";

const dialer = new JustCallDialer({
  dialerId: "justcall-dialer",
  onLogin: (data) => {
    console.log("Client receiving Logged in data: ", data);
  },
  onLogout: () => {
    console.log("Client receiving Logged out");
  },
  onReady: () => {
    console.log("Client received on ready callback");
  },
});

on Methods

The on method of the JustCallDialer class allows you to listen for events emitted by the JustCall Dialer. It takes two parameters:

Example:

dialer.on("call-ringing", (data) => {
  console.log("Client receiving call-ringing data: ", data);
});

dialer.on("call-answered", (data) => {
  console.log("Client receiving call-answered data: ", data);
});

dialer.on("call-ended", function (data) {
  console.log("Client receiving call-ended data: ", data);
});

unsubscribe(event: JustCallDialerEmittableEvent) method:

Unsubscribes from a specific event emitted by the JustCall dialer that you are currently listening to.

Parameters

Example

dialer.unsubscribe("call-ringing");

unsubscribeAll() method

Unsubscribes from all events that you are currently listening to, emitted by the JustCall dialer.

Example

dialer.unsubscribeAll();

ready method

The ready method of the JustCallDialer class ensures that the JustCall Dialer is ready for use before executing specific actions. It returns a Promise that resolves when the dialer is ready.

// Ensure the dialer is ready before using isLoggedIn and dialNumber methods
await dialer.ready();
const isLoggedIn = await dialer.isLoggedIn(); // returns true or false
dialer.dialNumber("+1234567890");

isLoggedIn Method

The isLoggedIn method of the JustCallDialer class checks whether the user is logged in to JustCall Dialer. It returns a Promise that resolves to a boolean value indicating the login status.

Note: Ensure that the dialer is in a ready state before calling this method.

Example:

await dialer.ready();
const isLoggedIn = await dialer.isLoggedIn(); // returns true or false

dialNumber Method

The dialNumber method of the JustCallDialer class prepopulates the dialer with the provided phone number. It takes one parameter:

Note: Ensure that the dialer is in a ready state before calling this method.

Example:

await dialer.ready();
dialer.dialNumber("+1234567890");

destroy Method

The destroy method of the JustCallDialer class is used to clean up and release resources when the JustCall Dialer instance is no longer needed. It performs the following actions:

Example:

dialer.destroy();

Event Data Types (Received in Respective Callbacks):

LoggedInEventData

This data object is passed to the onLogin callback function when the user logs in. It contains the following properties:

{
  "logged_in": true,
  "login_numbers": ["+1234567890", "+1987654321"],
  "user_info": {
    "email": "user@example.com",
    "name": "John Doe"
  }
}

CallRingingEventData

This data object is passed to the callback function when an incoming call starts ringing. It contains the following properties:

{
  "direction": "inbound",
  "from": "+1234567890",
  "to": "+1987654321",
  "call_sid": "abcdefgh123456"
}

CallAnsweredEventData

This data object is passed to the callback function when an incoming call is answered. It contains the following properties:

{
  "call_sid": "CAdemocallsid21345",
  "direction": "inbound",
  "answered_status": "answered"
}

CallEndedEventData

This data object is passed to the callback function when a call ends. It contains the following properties:

{
  "call_sid": "CAdemocallsid21345",
  "direction": "inbound",
  "duration": 120
}

Justcall Dialer Error Codes

The JustcallDialerErrorCode enum provides error codes for handling various scenarios in the JustCall Dialer SDK.

Error Codes:

These error codes are useful for identifying and handling different error scenarios in the JustCall Dialer SDK.

Authorizations for <iframe>

Please note that @justcall/justcall-dialer-sdk will produce an iframe with the following permissions granted:

<iframe
  allow="microphone; autoplay; clipboard-read; clipboard-write; hid"
  src="ttps://app.justcall.io/app/macapp/dialer_events"
  style="width='365px' height='610px'"
>
</iframe>

Contribution

We welcome contributions from the community to improve the JustCall Dialer SDK. To contribute, follow these steps:

  1. Make sure you have PNPM installed on your machine.

  2. Run the following command to create a changeset and generate a changelog:

    pnpm changeset
    
  3. This command will prompt you to select the type of update you're pushing (patch, minor, or major), and provide a description of the changes made.

  4. After creating the changeset and changelog, commit your changes using Git:

    git add .
    git commit -m "Your commit message"
    
  5. Push your changes to your fork of the repository and create PR.

Code coverage

Find our code coverage report here: https://saaslabsco.github.io/justcall-dialer-sdk/coverage/