yo1l/laravel-typeform
Composer 安装命令:
composer require yo1l/laravel-typeform
包简介
A simple Laravel Facade to retrieve typeform responses and to manage webhooks calls
README 文档
README
A simple Laravel 5 Facade to retrieve easily typeform responses and to validate/register/unregister webhooks.
Installation
Requirements
- php: >=7.0
- guzzlehttp/guzzle: ^6.3
- laravel/framework: ~5.4
Composer
composer require "yo1l/laravel-typeform"
Service Provider
The Yo1L\LaravelTypeForm\TypeFormServiceProvider is auto-discovered and registered by default, but if you want to register it yourself:
Add the ServiceProvider in config/app.php
'providers' => [
/*
* Package Service Providers...
*/
Yo1L\LaravelTypeForm\TypeFormServiceProvider::class,
]
Facade
The TypeForm facade is also auto-discovered, but if you want to add it manually:
Add the Facade in config/app.php
'aliases' => [
...
'TypeForm' => Yo1L\LaravelTypeForm\TypeFormFacade::class,
]
Config
To publish the config, run the vendor publish command:
php artisan vendor:publish --provider="Yo1L\LaravelTypeForm\TypeFormServiceProvider"
Sample of config/typeform.php
<?php
return [
'debug' => false,
'token' => env('TYPEFORM_TOKEN'),
'headers' => [],
'base_uri' => 'https://api.typeform.com/',
'webhook' => [
'base_uri' => env('TYPEFORM_WEBHOOK_BASE_URI', null), // if none app.url is used
'uri' => env('TYPEFORM_WEBHOOK_URI', '/api/webhook/typeform'),
'tag' => env('TYPEFORM_WEBHOOK_TAG', null),
'secret' => env('TYPEFORM_WEBHOOK_SECRET', null),
'verify_ssl' => env('TYPEFORM_WEBHOOK_VERIFY_SSL', true),
],
];
TYPEFORM_TOKEN is mandatory in order to retrieve all your data.
Getting Started
I higly advise to use the facade as all examples will use it.
use TypeForm;
Forms
Retrieve all your forms:
$formChunks = TypeForm::getFormsByChunk();
foreach ($formChunks as $forms) {
foreach ($forms['items'] as $form) {
Log::info($form['id']);
}
}
Here is a description of all request parameters.
Retrieve questions of a form
$jsonForm = TypeForm::getForm($this->formSlug);
foreach ($jsonForm['fields'] as $item) {
// $item is a question / section
Log::debug($item)
if ($item['type'] == 'group') {
foreach ($item['properties']['fields'] as $subItem) {
Log::debug($subItem);
}
}
}
Here is a description of all request parameters.
Responses
Retrieve all completed responses of a form:
$params = ['completed' => true];
foreach (TypeForm::getResponsesByChunk("MyFormId", $params) as $responses) {
/**
1 response = 1 submitted forms
Each response contains all answers (unordered)
*/
foreach ($responses['items'] as $jsonResponse) {
$submitted_at = Carbon::parse($jsonResponse['submitted_at']);
$id = $jsonResponse['token'];
foreach ($jsonResponse['answers'] as $jsonAnswer) {
/**
Store your answers ?
*/
}
}
}
Here is a JSON response explanation and all its parameters.
Webhooks
This package manages the secret if you have specified one in your config (TYPEFORM_WEBHOOK_SECRET).
Here is a description on webhooks security.
Register a webhook for a form:
TypeForm::registerWebhook('MyFormId');
Delete/unregister a webhook for a form:
TypeForm::deleteWebhook('MyFormId');
Validate a webhook call from your controller:
<?php
namespace App\Http\Controllers\API;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use TypeForm;
class TypeFormController extends Controller
{
public function __invoke(Request $request)
{
TypeForm::validatePayload($request);
$formId = $request->form_response['form_id'] ?? null;
abort_if($formId == null, 403);
/**
Do your stuff here
*/
return ['ok'];
}
}
yo1l/laravel-typeform 适用场景与选型建议
yo1l/laravel-typeform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.26k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yo1l/laravel-typeform 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yo1l/laravel-typeform 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-01