Skip to content

Commit

Permalink
feat: Add Greeting Options and Language
Browse files Browse the repository at this point in the history
-Add Greeting options in NgxFacebookMessengerOptions Interface
-Add Language Option in NgxFacebookMessengerOptions for configurable peer Region by default is en_US
-Add Default Constant for greeting when logged or not logged the user
  • Loading branch information
SkyZeroZx committed Oct 28, 2023
1 parent c966c06 commit 118c53e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ export enum SIZE_BUTTON_DESKTOP {
STANDARD = 'STANDARD_DESKTOP',
COMPACT = 'COMPACT_DESKTOP'
}


export const DEFAULT_GREETING = 'Hello, how can we help you?';
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import {
CUSTOMER_CHAT,
DEFAULT_GREETING,
SIZE_BUTTON_DESKTOP,
SIZE_BUTTON_MOBILE,
STYLE_BUTTON,
Expand Down Expand Up @@ -249,14 +250,15 @@ export class NgxFacebookMessengerComponent implements OnInit, OnChanges {
* The function injects the Facebook SDK asynchronously into the document.
*/
private injectFbSdkAsync(): void {
const language = this.ngxFacebookMessengerOptions?.language ?? 'en_US';
const fjs = this.document.getElementsByTagName('script')[0];
if (this.document.getElementById('facebook-jssdk')) return;
const js = this.document.createElement('script');
js.id = 'facebook-jssdk';
js.async = false;
js.defer = false;
js.crossOrigin = 'anonymous';
js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
js.src = `https://connect.facebook.net/${language}/sdk/xfbml.customerchat.js`;
fjs?.parentNode?.insertBefore(js, fjs);
}

Expand All @@ -277,9 +279,23 @@ export class NgxFacebookMessengerComponent implements OnInit, OnChanges {
'page_id',
this.ngxFacebookMessengerOptions.page_id
);

fbCustomerChat.setAttribute('attribution', 'biz_inbox');

fbCustomerChat.setAttribute(
'logged_in_greeting',
this.ngxFacebookMessengerOptions?.initPluginOptions?.logged_in_greeting ||
DEFAULT_GREETING
);

fbCustomerChat.setAttribute(
'logged_out_greeting',
this.ngxFacebookMessengerOptions?.initPluginOptions
?.logged_out_greeting || DEFAULT_GREETING
);

bodyElement.appendChild(fbRootElement);

bodyElement.appendChild(fbCustomerChat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface NgxFacebookMessengerOptions {
* Your required page_id for correctly work of real plugin facebook messenger
*/
page_id: string;
/**
* Optional option for defined language support by facebook plugin (review your language in documentation)
* @default 'en_US'
*/
language?: string;
/**
* Init Plugin Options
*/
Expand All @@ -25,6 +30,16 @@ export interface NgxFacebookMessengerOptions {
* @default 600
*/
debounceTime?: number;
/**
* When the user is logged with your account show a greeting text in the Facebook Plugin Messenger
* @default 'Hello, how can we help you?'
*/
logged_in_greeting?: string;
/**
* When the user not logged with your account show a greeting text in the Facebook Plugin Messenger
* @default 'Hello, how can we help you?'
*/
logged_out_greeting?: string;
};
/**
* Button Options for customization similar to a Facebook Plugin Official
Expand Down

0 comments on commit 118c53e

Please sign in to comment.