Skip to content

Instantly share code, notes, and snippets.

@MarcL
Created January 16, 2018 09:08
Show Gist options
  • Save MarcL/2edc4d95d5280bacc62fd95ebe14a2ec to your computer and use it in GitHub Desktop.
Save MarcL/2edc4d95d5280bacc62fd95ebe14a2ec to your computer and use it in GitHub Desktop.
Quick Node.js Express endpoint to redirect to a Messenger page
const express = require('express');
const app = express();
// Call this from JSON API like this:
//
// https://myserver.com/1920147214903175/GetEBook
//
app.get('/:fbpage/:reference', (request, response) => {
// Get the page and reference
// NOTE: There is no error checking here so it assumes that the parameters are always passed
const {fbpage, reference} = request.params;
// Create the Facebook Messenger URL
const messengerUrl = `https://m.me/${fbpage}?ref=${reference}`;
// Redirect to the page
response.redirect(messengerUrl);
});
app.listen(process.env.PORT || 8080, () => {
console.log('Your app is listening on port ' + listener.address().port);
});
@jinhoe
Copy link

jinhoe commented Jan 16, 2018

Thank you Marc for doing all this just for me! <3 <3
I'll check it out once I have the server setup. I'm rushing because I need to confirm my deliverable by this week. I'm so grateful, for your help. Appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment