Is it possible to trigger clientside JavaScript from a Messenger App?

#1

The framework operates entirely on webhooks. Each user interaction in the app is sent via a POST request to the URLs that you specified when originally setting up your app. As a result of this it isn’t possible to trigger clientside Javascript with a Messenger App.

1 Like

#2

+1 this. Changing the webpage UI / state based on messenger interactions would be gold.

0 Likes

#3

Unfortunately, it would also be pretty insecure – it’s very unlikely that we’ll enable this in the future.

2 Likes

#4

I’m not yet able to fully test this yet, but I think it may be possible to securely do this using the method below.

The idea would be to have a clientside js connect to your server via websocket or SSE. It would use the logged in intercom user_id as a client_id for identification.

When a Messenger App event happens, you can pass the json to your websock backend, process the event details and emit data back to the client which can then be used to modify the webpage UI/state.

1 Like

#5

From the documentation, it would appear that you can use client-side JavaScript in Sheets. But this would be isolated and wouldn’t be able to interact with anything outside the Sheet except through the API Intercom exposes.

1 Like

#6

Yes you’re exactly right Andrew. That renders the HTML page returned within the context of the iframe of the Messenger itself, rather than on the client DOM.

1 Like

#7

How would you get the user_id in the javascript on the website? In the past you could use Intercom(‘getVisitorId’), but that doesn’t seem to work anymore on the new client?

0 Likes

Is there a way to detect if Intercom Messenger is available?
#8

I noticed that too yesterday, thought it was an issue on my end. Seems to be working today.

For logged in users, you have access to the user_id since it’s a value you created.

EDIT: Intercom(‘getVisitorId’) is working on my dev account which was just setup today for messenger apps. My main live account, which is not yet upgraded to the new messenger, doesn’t work.

0 Likes

#9

@nana, funnily it is the exact opposite for me…

0 Likes

#10

@marcel that’s odd. I’ve just double checked with an account we have running the new Messenger and getVisitorId is working correctly :point_down:

0 Likes

#11

Hey @jonny, I uploaded my test HTML to a S3 button so I could show it to you, but the uploaded version does work. It is only the version that is served using ngrok that doesn’t output a valid visitorId. I also tried it on localhost and that also works fine. Apparently it is the combination ngrok/intercom that does not work but I don’t know what (I don’t see any difference in the HTML or headers). So it is not a big deal if it is only ngrok.

0 Likes

#12

Hey @marcel I actually think I know what’s going on here. Were you using ngrok as a host to actually boot into your workspace?

i.e. you went to https://ngrok.io/12323521341/mysite which loaded your page where the Messenger exists?

If you do that, it isn’t a proper domain, and we can’t place a cookie on the page, so every time you reload the page it’ll update the cookie and change visitor!

0 Likes

#13

@jonny, you can check it out here while i’m online: https://947ba44a.ngrok.io/

0 Likes

#14

Nice one! Yup that’s exactly it. We aren’t able to place a cookie on domains like that @marcel so that’s why that isn’t returning anything.

You should really only use ngrok for webhooks and then use localhost for development (because we can place cookies on localhost :+1: )

1 Like

#15

Yes, that is perfect for testing. :+1:

1 Like