PHP library
Webhook PHP library
A PHP library for pushing a message to a webhook, with a strategy for Slack channels. Install it with Composer as beehexa/webhook-php.
View on GitHubWhat it is
beehexa/webhook-php is a PHP library for pushing a message to a webhook. You build a message, pick a delivery strategy, and execute it in a hook context.
It is the library the Beehexa webhook module for Magento 2 relies on.
What it does
- A message builder: set the text, the entity ID and any extra fields such as event_name and entity_type.
- A strategy for each destination. The README shows the Slack channel strategy.
- A hook context that runs the chosen strategy on the message.
Requirements
- PHP 7.2, 8.0 or 8.1
Install
Composer
composer require beehexa/webhook-php
How to use it
Build a message, choose a strategy, and run it:
$messageBuilder = new Beehexa\WebhookPhp\Hook\Data\MessageBuilder();
$messageBuilder->setText('product');
$messageBuilder->setEntityId(123);
$messageBuilder->addField('event_name', 'update');
$messageBuilder->addField('entity_type', 'product');
$message = $messageBuilder->build();
// Slack strategy; the URL is a placeholder
$hookURL = 'https://hooks.slack.com/services/xxxx/xxxx/xxxx';
$hookStrategy = new Beehexa\WebhookPhp\Hook\Strategy\SlackChannel($hookURL);
$hookContext = new \Beehexa\WebhookPhp\HookContext($hookStrategy);
$hookContext->exec($message);
Good to know
- The sample follows the README; the Slack URL is a placeholder.
Related
Adapt to what you know, customize every flow, extend as you grow. Start with HexaSync