diff --git a/libs/ngx-facebook-messenger/src/lib/constant/customer-chat.constant.ts b/libs/ngx-facebook-messenger/src/lib/constant/customer-chat.constant.ts index e2368a9..60cdda1 100644 --- a/libs/ngx-facebook-messenger/src/lib/constant/customer-chat.constant.ts +++ b/libs/ngx-facebook-messenger/src/lib/constant/customer-chat.constant.ts @@ -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?'; \ No newline at end of file diff --git a/libs/ngx-facebook-messenger/src/lib/ngx-facebook-messenger.component.ts b/libs/ngx-facebook-messenger/src/lib/ngx-facebook-messenger.component.ts index 3ca7a56..3ef1d51 100644 --- a/libs/ngx-facebook-messenger/src/lib/ngx-facebook-messenger.component.ts +++ b/libs/ngx-facebook-messenger/src/lib/ngx-facebook-messenger.component.ts @@ -16,6 +16,7 @@ import { import { CUSTOMER_CHAT, + DEFAULT_GREETING, SIZE_BUTTON_DESKTOP, SIZE_BUTTON_MOBILE, STYLE_BUTTON, @@ -249,6 +250,7 @@ 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'); @@ -256,7 +258,7 @@ export class NgxFacebookMessengerComponent implements OnInit, OnChanges { 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); } @@ -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); } diff --git a/libs/ngx-facebook-messenger/src/lib/types/ngx-facebook-messenger.interface.ts b/libs/ngx-facebook-messenger/src/lib/types/ngx-facebook-messenger.interface.ts index 5398b2c..b17b8d6 100644 --- a/libs/ngx-facebook-messenger/src/lib/types/ngx-facebook-messenger.interface.ts +++ b/libs/ngx-facebook-messenger/src/lib/types/ngx-facebook-messenger.interface.ts @@ -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 */ @@ -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