Created
June 19, 2017 15:21
-
-
Save atwj/e4362289b068bd7779fec3de0789748d to your computer and use it in GitHub Desktop.
Messenger Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Sign Up</title> | |
| <!-- Compiled and minified CSS --> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css"> | |
| <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | |
| <!-- Compiled and minified JavaScript --> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script> | |
| <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
| crossorigin="anonymous"></script> | |
| <style> | |
| .btn { | |
| width: 100%; | |
| text-align: center; | |
| vertical-align: middle; | |
| font-size: large; | |
| display: inline-block !important; | |
| } | |
| </style> | |
| <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"> | |
| </head> | |
| <body> | |
| <script> | |
| (function(d, s, id){ | |
| var js, fjs = d.getElementsByTagName(s)[0]; | |
| if (d.getElementById(id)) {return;} | |
| js = d.createElement(s); js.id = id; | |
| js.src = "//connect.facebook.com/en_US/messenger.Extensions.js"; | |
| fjs.parentNode.insertBefore(js, fjs); | |
| }(document, 'script', 'Messenger')); | |
| var verify = function(context, success, error){ | |
| var currentlocation = window.location | |
| var hostname = currentlocation.hostname | |
| var url = 'https://'+hostname+'/verify?signed_request='+context.signed_request | |
| $.get(url, function(data){ | |
| var parsedData = JSON.parse(data) | |
| if(!parsedData.error){ | |
| parsedData.psid = context.psid | |
| success(parsedData); | |
| } | |
| }) | |
| } | |
| $(function(){ | |
| window.extAsyncInit = function() { | |
| MessengerExtensions.getSupportedFeatures(function (result) { | |
| var features = result.supported_features; | |
| if (features.indexOf('context') === -1) { | |
| alert('Yikes! It seems like you are not using the latest version of messenger. Do update and try again' ) | |
| MessengerExtensions.requestCloseBrowser(function(result){},function(error){}); | |
| } | |
| // If context available, get context | |
| MessengerExtensions.getContext('APP_ID', function(context){ | |
| function onSuccess(data){ | |
| $('#first_name').val(data.first_name) | |
| $('#last_name').val(data.last_name) | |
| $('#psid').val(data.psid) | |
| } | |
| function onError(error){} | |
| //verify signed_request | |
| Raven.context(verify(context, onSuccess, onError)) | |
| }, function (err){Raven.captureMessage(err)}); | |
| }, function (err) { | |
| alertAndCloseBrowser() | |
| }); | |
| } | |
| $('form').submit(function(e){ | |
| MessengerExtensions.requestCloseBrowser(function(result){},function(error){}); | |
| }) | |
| }); | |
| </script> | |
| .... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment