howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.49k stars 2.28k forks source link

Send message from the server #650

Closed PierreMarieRiviere closed 6 years ago

PierreMarieRiviere commented 7 years ago

I need to send a message after a user opens (or better, after he closes) a webview in Messenger. How can I do this?

In facebook.js

webserver.get('/index', isLoggedIn, function(req, res){
            res.render('index.ejs',{
                    user : req.user 
                });
            req.on("end", function() {console.log("SEND A MESSAGE?"); });
GautierT commented 7 years ago

Maybe by broadcasting an event to your botkit controller ? I will try that. I need it too !

ouadie-lahdioui commented 7 years ago

Guys, you can do that with Messenger Extensions JS SDK, and Her's the documentation

thierryskoda commented 7 years ago

@ouadie-lahdioui The only problem with Messenger Extensions is that it only works for mobile devices no?

ouadie-lahdioui commented 7 years ago

According to some people on internet, messenger Extensions only work on iOS and Android, but i can't found the confirmation on Facebook docs

jonchurch commented 7 years ago

The docs say extensions work on iOS and Android, but not messenger.com (aka desktop user)

Fallback url is used when user is on desktop, in that case you aren't going to close a webview but redirect the user back to your bot's m.me url. Whatever logic you use for triggering a message at the same time as that would be pretty similar across extensions and desktop.

Right before webview close or desktop redirect, I'd make a POST request to a specific endpoint on your botkit server (sending the userID along so we know who to contact), which would then trigger a custom botkit event that would bot.say at that particular user.

ALSO this assumes that the webview session is terminated by the user through some UI on the page. I don't personally know how to handle sending a request once the user closes a tab/window, I think it would be easier to just trigger that event with a user action, easier to predict and creates a smooth flow.

ouadie-lahdioui commented 7 years ago

Ahaah :flushed:

@jonchurch +1 for your proposition

jonchurch commented 7 years ago

Actually on desktop its probably gonna open a tab, so a redirect wouldnt work likely.