2017 © Pedro Peláez
 

library helpscout-dynamic-app

A library to assist the creation of Help Scout dynamic apps

image

tompedals/helpscout-dynamic-app

A library to assist the creation of Help Scout dynamic apps

  • Wednesday, September 28, 2016
  • by tompedals
  • Repository
  • 1 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

HelpScout Dynamic App Server

A simple library to verify Help Scout dynamic app requests and respond accordingly. Forked from the official library to add support for PSR-7 HTTP message interfaces., (*1)

Installation

This is installable via Composer as tompedals/helpscout-dynamic-app:, (*2)

composer require tompedals/helpscout-dynamic-app

Example

Note: The following example uses zendframework/zend-diactoros as the HTTP message implementation., (*3)

Handle a request

The request will be verified using the given secret and signature from the request headers., (*4)

use TomPedals\HelpScoutApp\AppRequestFactory;
use Zend\Diactoros\ServerRequestFactory;

$factory = new AppRequestFactory('secret');
$request = $factory->create(ServerRequestFactory::fromGlobals());

/** @var TomPedals\HelpScoutApp\Model\Customer */
$customer = $request->getCustomer();

/** @var TomPedals\HelpScoutApp\Model\Mailbox */
$mailbox = $request->getMailbox();

/** @var TomPedals\HelpScoutApp\Model\Ticket */
$ticket = $request->getTicket();

/** @var TomPedals\HelpScoutApp\Model\User */
$user = $request->getUser();

Respond to a request

Set the HTML on the response and get the correct schema for the JSON response., (*5)

use TomPedals\HelpScoutApp\AppResponse;
use Zend\Diactoros\Response\JsonResponse;

$response = new AppResponse('

Test

'); $jsonResponse = new JsonResponse($response->getData());

Controller action

A PSR-7 compatible action is available to handle the request and respond accordingly. The action is an invokable class that can be used with Slim, Symfony, Zend Framework, etc., (*6)

Implement the AppHandlerInterface to handle the AppRequest and return the HTML to be rendered within the Help Scout sidebar., (*7)

class AppHandler implements AppHandlerInterface
{
    public function handle(AppRequest $request)
    {
        // Find customer information
        // Render the template
        // Return the HTML response

        return '<h4>This customer is awesome</h4>';
    }
}

Pass the AppHandler implementation when constructing the action., (*8)

use TomPedals\HelpScoutApp\AppAction;
use TomPedals\HelpScoutApp\AppHandlerInterface;
use TomPedals\HelpScoutApp\AppRequestFactory;

// implements AppHandlerInterface
$handler = new AppHandler();

$action = new AppAction(new AppRequestFactory('secret'), $handler);
$response = $action($request, $response);

The Versions

28/09 2016

dev-master

9999999-dev

A library to assist the creation of Help Scout dynamic apps

  Sources   Download

MIT

The Requires

 

The Development Requires

helpscout

28/09 2016

0.2.1

0.2.1.0

A library to assist the creation of Help Scout dynamic apps

  Sources   Download

MIT

The Requires

 

The Development Requires

helpscout

22/09 2016

0.2.0

0.2.0.0

A library to assist the creation of Help Scout dynamic apps

  Sources   Download

MIT

The Requires

 

The Development Requires

helpscout

22/09 2016

0.1.0

0.1.0.0

A library to assist the creation of Help Scout dynamic apps

  Sources   Download

MIT

The Requires

 

The Development Requires

helpscout