rapid prototyping chatter with a php/hack canvas app on heroku

50
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku Rodney White President, The Acceleration Agency @rodney_white

Upload: salesforce-developers

Post on 01-Jul-2015

337 views

Category:

Technology


0 download

DESCRIPTION

Join us for a live code demonstration of creating a PHP/Hack app and integrating it with Chatter via Force.com Canvas. We will provide a process and framework to rapidly prototype Canvas apps within minutes, rather than days or months. In the session, we'll show you how we built prototypes based on ideas from the Salesforce Ideas site such as real-time translation to voice memos. At the end of the session, we will provide the prototyping framework for download.

TRANSCRIPT

Page 1: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRodney White

President, The Acceleration Agency

@rodney_white

Page 2: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

The goal is to provide a process and framework to rapidly prototype

Force.com Chatter Canvas apps within minutes, not days or months

Page 3: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Agenda

1. Introduction

2. Rapid Prototyping Basics

3. Tech Basics

4. Time to code

5. Questions

Page 4: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Rodney WhiteFounder, The Acceleration Agency

Page 5: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

The Acceleration Agency leverages

iterative philosophies and methodologies to

innovate new products, platforms, and services.

We are Designers.

We are Makers.

We are Learners.

Page 6: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Use to introduce a

demo, video, Q&A, etc. Rapid Prototyping Basics

Page 7: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Rapid Prototyping Basics*Maximize the Rate of Learning by

Minimizing the time to try ideas - Tom Chi

Rule #1: Find the quickest path to the experience.Rule #2: Making is the best kind of thinking.Rule #3: Use materials that move at the speed of thought.Rule #4: Your user’s reality is the medium.Rule #5: Knowing is the enemy of learning.Rule #6: “The first draft of anything is shit.” - Ernest Hemingway

* Some rules are courtesy of Tom Chi. Please watch: https://www.youtube.com/watch?v=DkyMCCnNI3Q to learn more

Page 8: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Rapid Prototyping Basics*

Rate based goals

By the time you try 1 iteration

-> 5% chance of success

By the time you try 20 iterations

-> 64% chance of success

By the time you try 50 iterations

-> 92% chance of success

Page 9: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Use to introduce a

demo, video, Q&A, etc. Chatter Basics

Page 10: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Chatter Basics

Publisher

Chatter lets you create instant actions that are instantly mobile. For any business process. Expense reports, support cases, orders, and more. Customize actions for your company, and even integrate third party apps. So you can get more done in the feed from any device.

Page 11: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Chatter Basics

Feeds and Feed Items

Do everything in the feed. Keep up with critical projects, topics, and teams. Work together on sales opportunities, service cases, and marketing campaigns. Capture organizational knowledge in a single location. Drive progress from anywhere.

Page 12: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Use to introduce a

demo, video, Q&A, etc. Canvas App Basics

Page 13: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App Basics

With the force.com Canvas SDK, you can now integrate your Web app with the trusted salesforce.com platform: Your language, your code

- Salesforce

Page 14: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App Basics

Enable Publisher, Feed, and

VF page access

During Prototype

Allow Full access

Enable oAuth

Enable

Canvas Enable

Signed Request

Setup -> App Setup -> Create -> Apps -> Connected App -> New Button

Page 15: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App BasicsSetup -> App Setup -> Create -> Apps -> Global Actions -> Actions -> New Action Button

ChooseCustom Canvas

Page 16: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App BasicsSetup -> App Setup -> Create -> Apps -> Global Actions -> Publisher Layouts -> Edit Action

Drag new actionto Publisher Actions

Page 17: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App Basics

New canvas app action is now

available Chatter

Page 18: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Canvas App Basics

iFrame of the canvas app in the publisher

iFrame of the canvas app in the feed

Page 19: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Use to introduce a

demo, video, Q&A, etc. Heroku Basics

Page 20: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Heroku Basics

Heroku is a cloud platform as a service

supporting several programming languages. Heroku was acquired by

Salesforce.com in 2010.

Page 21: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Heroku Basics

Heroku With Heroku, Developers may now deploy distributed and scalable code in minutes.

Page 22: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Heroku BasicsTerminology

- Procfiles - named commands that you may want executed.- Applications - consist of your source code, a description of any dependencies,

and a Procfile.- Slug - is an application bundle of your source, fetched dependencies, the language

runtime, and compiled/generated output of the build system - ready for execution.- Buildpacks - lie behind the slug compilation process. Buildpacks take your

application, its dependencies, and the language runtime, and produce slugs.- Dynos - are isolated, virtualized Unix containers, that provide the environment

required to run an application.

Page 23: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Heroku BasicsAs of May 2014, Heroku now offers an official PHP buildpack which supports:

Packaging via ComposerFirst class frameworks

- Symfony - Laravel

Heroku XL SupportPHP 5.5 SupportHHVM/HACK 3.2 SupportNGINX SupportApache Support

Page 24: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Heroku BasicsEnabling HHVM + NGINX

Available procfilesheroku-hhvm-apache2 heroku-hhvm-nginxheroku-php-apache2heroku-php-nginx

Procfile example for nginx+hhvm$ echo 'web: vendor/bin/heroku-hhvm-nginx' > Procfile

Page 25: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Use to introduce a

demo, video, Q&A, etc. Time To Code!

Page 26: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 1Hello World of Heroku

Page 27: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Hello World on heroku

echo '<?php echo "Hello World!"; ?>' > index.phpecho '{}' > composer.jsongit initgit add .git commit -m "Initial import of Hello Heroku"heroku create git push heroku masterheroku open

http://taa.io/df14/app1/

Page 28: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Hello World 1.1 on heroku (with HHVM/NGINX support)

This enables HHVM/HACK on heroku!

echo '<?php phpinfo();' > index.phpecho '{"require": {"php": "*","hhvm": ">= 3.1"}}' > composer.jsonecho 'web: vendor/bin/heroku-hhvm-nginx' > Procfilegit initgit add .git commit -m "Initial import of Hello Heroku"heroku create git push heroku masterheroku open

http://taa.io/df14/app1/

Page 29: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Hello World 1.1

Let’s try it in the terminal

http://taa.io/df14/app1/

Page 30: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 2Parse Force.com signed requests

Proper Folder Structure

Page 31: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Parsing Force.com signed requests

PHP/Hack on Heroku

Signed Request

Force.com Signed Request

http://taa.io/df14/app2/

Page 32: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Parsing Signed request from Force.com

// lifted from https://github.com/joshbirk/Canvas-PHP Canvas via SignedRequest/POST, the authentication should be passed via the signed_request header

$signedRequest = @$_REQUEST['signed_request']; $consumer_secret = @$_ENV['consumer_secret']; if ($signedRequest == null || $consumer_secret == null) { echo "Error: Signed Request or Consumer Secret not found"; exit; }

//decode the signedRequest $sep = strpos($signedRequest, '.'); $encodedSig = substr($signedRequest, 0, $sep); $encodedEnv = substr($signedRequest, $sep + 1); $calcedSig = base64_encode(hash_hmac("sha256", $encodedEnv, $consumer_secret, true)); if ($calcedSig != $encodedSig) { echo "Error: Signed Request Failed. Is the app in Canvas?"; exit; }

//decode the signedRequest $sep = strpos($signedRequest, '.'); $encodedSig = substr($signedRequest, 0, $sep); $encodedEnv = substr($signedRequest, $sep + 1);

//decode the signed request object $req = json_decode(base64_decode($encodedEnv));

//As of Spring '13: SignedRequest has a client object which holds the pertinent authentication info $access_token = $req->client->oauthToken; $instance_url = $req->client->instanceUrl;

$_SFDC_REQ = $req;

error_log(json_encode($_SFDC_REQ));

$location = @$req->context->environment->displayLocation;

http://taa.io/df14/app2/

Page 33: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Integrating with Force.com signed requests

- Using composer for package management- Configure NGINX via Procfile- Proper folder structure and router- Parse Force.com signed requests

Folder StructurePublic —static files (i.e. js/css files)Handlers — i.e. controllers’ish

canvas — a handler for a canvas appViews — presentation layer (mustache templates)Webroot — entry point for web requestNginx.conf — custom config for nginxProcfile — custom config to enable nginx + hhvm

http://taa.io/df14/app2/

Page 34: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

- A few local dev gotchas- Localhost mock for heroku's $_ENV config

- config.ini + parse_ini_file()

if (php_sapi_name() == 'cli-server') {$ini_array = @parse_ini_file(__DIR__."/../config.ini");

foreach($ini_array as $key => $value){$_ENV[$key] = $value;

}}

http://taa.io/df14/app2/

Page 35: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

- A few local dev gotchas- https://localhost/

- NodeJS + NPM to the rescue

var fs = require('fs');

var http = require(‘http'), httpProxy = require(‘http-proxy');

httpProxy.createServer({ target: { host: 'localhost', port: 80 }, ssl: { key: fs.readFileSync('keys/server.key', 'utf8'), cert: fs.readFileSync('keys/server.crt', 'utf8') }}).listen(443);

http://taa.io/df14/app2/

Page 36: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 2See it in Action

http://taa.io/df14/app2/

Page 37: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Sample App 2

http://taa.io/df14/app2/

Page 38: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 3Let’s build something…A Babel Fish*

* Thanks Douglas Adams

Page 39: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Let’s build something…A Babel Fish

Three parts to the Babel Fish chatter app- Publisher

- Text Input- Feed Item

- Dynamic translation- Integration with 3rd party api

- Google Translate API

* bonus: VisualForce integration with a Canvas App

Page 40: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 3 (A Babel Fish)See it in Action

Page 41: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Sample App 3 (A Babel Fish)

Words into the babel fish

Auto Translated into native language

Page 42: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Sample App 3 (A Babel Fish on a Visual Force Page)

Time To Code!

Subject of the Case

Auto Translated into native language

Page 43: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Sample App 3 (A Babel Fish)Want an installable AppExchange version?

http://taa.io/df14/translator/

Time To Code!

Page 44: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 4Let’s build something…Voice Memo

(Chrome and Firefox only)

Page 45: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Let’s build something…Voice Memos

Three parts to the VoiceMemo chatter app- Publisher

- HTML5 Audio Input- Feed Item

- Audio Playback- Integration with 3rd party persistence layer (S3)

- CDN playback

Page 46: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!

Sample App 4 (Voice Memo)See it in Action

Page 47: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Time To Code!Sample App 4 (Voice Memo)

Record the Voice memo with HTML5

only(Chrome/Firefox only)

Audio Playback in the feed

Page 48: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Sample App 4 (Voice Memo)Want an installable AppExchange version?*

*?

http://taa.io/df14/voicememo/

*No commercial support

Time To Code!

Page 49: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku

Rodney WhiteRodney White@[email protected]

http://taa.io/df14/

Want the framework?

Page 50: Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku