tompedals/helpscout-dynamic-app 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tompedals/helpscout-dynamic-app

Composer 安装命令:

composer require tompedals/helpscout-dynamic-app

包简介

A library to assist the creation of Help Scout dynamic apps

关键字:

README 文档

README

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.

Installation

This is installable via Composer as tompedals/helpscout-dynamic-app:

composer require tompedals/helpscout-dynamic-app

Example

Note: The following example uses zendframework/zend-diactoros as the HTTP message implementation.

Handle a request

The request will be verified using the given secret and signature from the request headers.

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.

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

$response = new AppResponse('<h4>Test</h4>');
$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.

Implement the AppHandlerInterface to handle the AppRequest and return the HTML to be rendered within the Help Scout sidebar.

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.

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);

统计信息

  • 总下载量: 77
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固