aircall / aircall-everywhere

SDK to embed and communicate to Aircall phone in any web page
https://aircall.github.io/aircall-everywhere
25 stars 16 forks source link

How to use the Aircall Everywhere in any CRM ?

Include this project in your dependency

npm install -s aircall-everywhere

Constructor

You need to create an instance to use the library. The constructor has a settings argument:

Example:

import AircallPhone from 'aircall-everywhere';

const aircallPhone = new AircallPhone({
  onLogin: (settings) => {
    console.log('phone loaded');
    doStuff();
  },
  onLogout: () => {},
  domToLoadPhone: '#phone',
  integrationToLoad: 'zendesk',
  size: 'big',
});

Settings passed in the onLogin callback contains info about the user and integration and looks like this:

{
  user: {
    email: 'john@company.com',
    first_name: 'John',
    last_name: 'Smith',
    company_name: 'Super Company Inc'
  },
  settings: {
    <specific_integration_settings>
  }
}

isLoggedIn method

In addition to the onLogin and onLogout callbacks, a isLoggedIn method is provided that will directly asks the phone about its status. The result is a boolean.

Example:

aircallPhone.isLoggedIn((res) => {
  console.log('login status:', res);
});

on & send

You can send messages to the phone and listen messages coming from it.

events from the phone:

All events from the phone with the payload associated:

call_id parameter is a number per call. duration is in seconds. All numbers are sent in the e.164 format.

Example:

aircallPhone.on('incoming_call', (callInfos) => {
  console.log(`Call from ${callInfos.from} to ${callInfos.to}`);
  doStuff();
});

events the phone listens to:

Example:

aircallPhone.send('dial_number', { phone_number: number }, (success, data) => {
  console.log('success of dial:', success);
});

The callback of the send method has two arguments:

All generic errors from send:

List of events:

more events to come...

removeListener method

You can remove a listener added by on with this method.

<iframe> authorizations

Please be aware that aircall-everywhere will generate an iframe with following allow attributes.

<iframe
  allow="microphone; autoplay; clipboard-read; clipboard-write; hid"
  src="https://phone.aircall.io?integration=generic"
  style="height:100%; width:100%;"
>
</iframe>

If you need to embed aircall-everywhere in an <iframe> you own, please be sure to propagate the allow attributes like so

<!-- your iframe -->
<iframe src="https://github.com/aircall/aircall-everywhere/raw/master/your src here" allow="camera; microphone; clipboard-read; clipboard-write; hid">
  <!-- iframe generated by aircall-everywhere -->
  <iframe
    allow="microphone; autoplay; clipboard-read; clipboard-write; hid"
    src="https://phone.aircall.io?integration=generic"
    style="height:100%; width:100%;"
  >
  </iframe>
</iframe>

The clipboard API is not accessible through <iframe> since Chrome v81 and a policy has been added since Chrome v85. That's why aircall-everywhere needs these attributes. More info here.

Development

You can run the demo webpage with: yarn start

tests are available: yarn test yarn test-watch yarn coverage

to create a new version: yarn version --patch|--minor|--major and create a PR. The CI will publish the new version after manual approval.

Code coverage

A code coverage report is available here.