Getting PSID: Angular2 and Facebook messenger extension

Viewed 548

It's been a week since I started struggling with this problem.

I want to create a webview for a Facebook bot and all I want is to get the psid of the user. Everything smooth with plain javascript: I can use window.extAsyncInit() and wait for Facebook initialization...but what can I do if I am using Angular2?

I tried adding this to @Component:

host: {
    '(window:extAsyncInit)': 'this.facebookinit($event)'
  }

I tried to mimic the behavior of Scroll listener using this inside the component:

@HostListener('window:extAsyncInit', ['$event']) onFbEvent($event){
    console.log("called");
  } 

And I tried every possible combination I found in stackoverflow...but I am still blocked. For the moment I solved calling MessengerExtensions only in response to certain click events, but now I really need it to be available when the webview appears and the only way I have to avoid the undefined problem is to use extAsyncInit.

Can you please help me?

Update: I have tried also with Renderer2 listen and by copying the facebook javascript code into the asset folder and declaring MessengerExtension right under the list of imports. But still no results!

1 Answers
Related