Add Facebook Customer Chat Plugin to an Angular App

Facebook has a customer chat widget to assist businesses to engage with customers. With over 2 Billion users, Majority of your customer, if not all, are somehow on Facebook. If you are looking for a free customer chap widget for your website, then Facebook is a very good option.

It is very easy to use, and all messages come to your Facebook page inbox. And since Facebook has apps for almost all devices out there, then you can reply to your customers from anywhere you are. Very handy for small business. You can learn more about this plugin here.

Add Facebook Customer Chat Plugin to an Angular App

Add Facebook Customer Chat Plugin to an Angular App

Whitelist the Domain of your Website(s)

The first step we are going to take is to whitelist the domain of your website so as the plugin can be rendered on your webpage. To do this head over to your Facebook page, and then follow the steps below:

  1. Click Settings at the top of your Page
  2. Click Messenger Platform on the left
  3. Edit whitelisted domains for your page in the Whitelisted Domains section

Integrate with your Angular App

To add it to your Angular app, you need the Facebook JavaScript SDK, which you can find here. The quickest way to do this to include into your index.html file as shown below:

<script type="text/javascript" src=""></script>

Note:  Add it just before closing the body tag so that it doesn’t affect the loading speeds of your app.

Assuming you have successfully added the snippets to your app index.html, you need an Angular Module to initialize the Customer Chat Plugin and Render it in your browser. For this, I am using ngx-facebook. It offers a lot of functionality out of the box, which you can learn more about here.

Install ngx-facebook using npm or yarn as shown below:

npm i --save ngx-facebook
yarn add ngx-facebook

And then import it into your AppModule as illustrated below:

import { FacebookModule } from 'ngx-facebook';

  imports: [
export class AppModule { }

Assuming you have installed and imported the Angular Module successfully, then all that is remaining is adding the plugin to your component pages you want it to appear. I suggest adding it to the root component of your app if you wish it to be rendered in all pages of your application. In your component html file, add the following snippet from Facebook:

<div class="fb-customerchat"

Make sure to replace all variables inside angle brackets (including the angle brackets) with variables specific to your app. And finally, initialize the component inside your component class constructor or initializer as shown below:

First, import FacebookService and InitParams from ngx-facebook:

import { FacebookService, InitParams } from "ngx-facebook";

And then, inject it to your component and initialize the Facebook customer chat plugin

constructor(private fb: FacebookService) {
    let initParams: InitParams = {
      xfbml: true,
      version: "v2.8"


Note: If you are having trouble finding the page id of your Facebook page, you can use the following link.