定制 codebar-ag/laravel-zendesk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codebar-ag/laravel-zendesk

Composer 安装命令:

composer require codebar-ag/laravel-zendesk

包简介

Zendesk integration with Laravel

README 文档

README

Latest Version on Packagist Total Downloads GitHub-Tests GitHub Code Style PHPStan Dependency Review

This package was developed to give you a quick start to creating tickets via the Zendesk API.

💡 What is Zendesk?

Zendesk is a cloud-based help desk management solution offering customizable tools to build customer service portals, knowledge base and online communities.

🛠 Requirements

Package PHP Laravel Zendesk
v13.0 ^8.3 - ^8.5 13.x
v12.0 ^8.2 - ^8.4 12.x
v11.0 ^8.2 - ^8.3 11.x
v1.0 ^8.2 10.x

Authentication

The currently supported authentication methods are:

Method Supported
Basic Auth
API token
OAuth access token

⚙️ Installation

You can install the package via composer:

composer require codebar-ag/laravel-zendesk

Optionally, you can publish the config file with:

php artisan vendor:publish --provider="CodebarAg\Zendesk\ZendeskServiceProvider" --tag="config"

You can add the following env variables to your .env file:

ZENDESK_SUBDOMAIN=your-subdomain #required
ZENDESK_AUTHENTICATION_METHOD=token #default ['basic', 'token']
ZENDESK_EMAIL_ADDRESS=test@example.com #required
ZENDESK_API_TOKEN=your-api-token #required only for token authentication
ZENDESK_API_PASSWORD=your-password #required only for basic authentication

Note: We handle base64 encoding for you so you don't have to encode your credentials.

You can retrieve your API token from your Zendesk Dashboard

Usage

To use the package, you need to create a ZendeskConnector instance.

use CodebarAg\Zendesk\ZendeskConnector;
...

$connector = new ZendeskConnector();

Requests

The following requests are currently supported:

Request PHP class Supported
List tickets AllTicketsRequest
Count tickets CountTicketsRequest
Get ticket SingleTicketRequest
Create ticket CreateSingleTicketRequest
Create attachment CreateAttachmentRequest

Responses

The following responses are currently supported for retrieving the response body:

Response Methods Description Supported
body Returns the HTTP body as a string
json Retrieves a JSON response body and json_decodes it into an array.
object Retrieves a JSON response body and json_decodes it into an object.
collect Retrieves a JSON response body and json_decodes it into a Laravel collection. Requires illuminate/collections to be installed.
dto Converts the response into a DTO. This package provides DTOs for the requests above; Saloon also allows custom DTOs.

See https://docs.saloon.dev/the-basics/responses for more information.

Enums

We provide enums for the following values:

Enum Values
TicketPriority 'urgent', 'high', 'normal', 'low'
TicketType 'incident', 'problem', 'question', 'task'
MalwareScanResult 'malware_found', 'malware_not_found', 'failed_to_scan', 'not_scanned'

Note: When using the dto method on a response, the enum values will be converted to their respective enum class.

Zendesk API and DTO coverage

Official ticket JSON is documented in the Zendesk Tickets API. SingleTicketDTO maps a large subset of fields returned by Zendesk; it is not guaranteed to include every property the API may return. For example, the docs show custom_status_id and generated_timestamp on ticket objects; those keys are not mapped on SingleTicketDTO today.

DTOs

We provide DTOs for the following:

DTO PHP class
AttachmentDTO CodebarAg\Zendesk\Dto\Tickets\Attachments\AttachmentDTO
ThumbnailDTO CodebarAg\Zendesk\Dto\Tickets\Attachments\ThumbnailDTO
UploadDTO CodebarAg\Zendesk\Dto\Tickets\Attachments\UploadDTO
CommentDTO CodebarAg\Zendesk\Dto\Tickets\Comments\CommentDTO
AllTicketsDTO CodebarAg\Zendesk\Dto\Tickets\AllTicketsDTO
CountTicketsDTO CodebarAg\Zendesk\Dto\Tickets\CountTicketsDTO
SingleTicketDTO CodebarAg\Zendesk\Dto\Tickets\SingleTicketDTO

Note: This is the preferred way to work with requests and responses. You can still use the json, object, and collect methods, and pass arrays into requests where supported.

Examples

Create a ticket

use CodebarAg\Zendesk\Requests\CreateSingleTicketRequest;
use CodebarAg\Zendesk\Dto\Tickets\SingleTicketDTO;
use CodebarAg\Zendesk\Dto\Tickets\Comments\CommentDTO;
use CodebarAg\Zendesk\Enums\TicketPriority;
...

$ticketResponse = $connector->send(
    new CreateSingleTicketRequest(
        SingleTicketDTO::fromArray([
            'comment' => CommentDTO::fromArray([
                'body' => 'The smoke is very colorful.',
            ]),
            'priority' => TicketPriority::URGENT,
            "subject" => "My printer is on fire!",
            "custom_fields" => [
                [
                    "id" => 12345678910111,
                    "value" => "Your custom field value"
                ],
                [
                    "id" => 12345678910112,
                    "value" => "Your custom field value 2"
                ],
            ],
        ])
    )
);

$ticket = $ticketResponse->dto();

List all tickets

use CodebarAg\Zendesk\Requests\AllTicketsRequest;
...

$listTicketResponse = $connector->send(new AllTicketsRequest());
$listTicketResponse->dto();

Count all tickets

use CodebarAg\Zendesk\Requests\CountTicketsRequest;
...

$countTicketResponse = $connector->send(new CountTicketsRequest());
$countTicketResponse->dto();

Get a ticket

use CodebarAg\Zendesk\Requests\SingleTicketRequest;
...

$ticketId = 1;

$ticketResponse = $connector->send(new SingleTicketRequest($ticketId));
$ticketResponse->dto();

Upload an attachment

use CodebarAg\Zendesk\Requests\CreateAttachmentRequest;
use CodebarAg\Zendesk\Requests\CreateSingleTicketRequest;
use CodebarAg\Zendesk\Dto\Tickets\SingleTicketDTO;
use CodebarAg\Zendesk\Dto\Tickets\Comments\CommentDTO;
use Illuminate\Support\Facades\Storage;

$uploadResponse = $connector->send(
    new CreateAttachmentRequest(
        fileName: 'someimage.png',
        mimeType: Storage::disk('local')->mimeType('public/someimage.png'),
        stream: Storage::disk('local')->readStream('public/someimage.png')
    )
);

$token = $uploadResponse->dto()->token;

$ticketResponse = $connector->send(
    new CreateSingleTicketRequest(
        SingleTicketDTO::fromArray([
            'comment' => CommentDTO::fromArray([
                ...
                'uploads' => [
                    $token,
                ],
            ]),
        ])
    )
);

$ticket = $ticketResponse->dto();

🚧 Testing

Copy your own phpunit.xml-file.

cp phpunit.xml.dist phpunit.xml

Run the tests:

./vendor/bin/pest

📝 Changelog

Please see CHANGELOG for recent changes.

✏️ Contributing

Please see CONTRIBUTING for details.

composer test

Code Style

./vendor/bin/pint

🧑‍💻 Security Vulnerabilities

Please review our security policy on reporting security vulnerabilities.

🙏 Credits

🎭 License

The MIT License (MIT). Please have a look at License File for more information.

codebar-ag/laravel-zendesk 适用场景与选型建议

codebar-ag/laravel-zendesk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Zendesk」 「codebar-ag」 「laravel-zendesk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codebar-ag/laravel-zendesk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codebar-ag/laravel-zendesk 我们能提供哪些服务?
定制开发 / 二次开发

基于 codebar-ag/laravel-zendesk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-01