Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Latest commit

 

History

History
28 lines (19 loc) · 1.05 KB

events.md

File metadata and controls

28 lines (19 loc) · 1.05 KB

Events

In some scenarios, you might want to keep track of what data is passed to Slack, and what data is returned. For this, two events have been made available that you can listen to: EVENT_REQUEST and EVENT_RESPONSE.

Below is an example of how you could use this to display debugging information to a command-line user (e.g. in a Command):

<?php

$apiClient = new ApiClient('your-token-here');

$apiClient->addRequestListener(function (RequestEvent $event) {
    echo "Sent payload:\n";
    var_dump($event->getRawPayload()); // array containing the data that was sent to Slack
});

$apiClient->addResponseListener(function (ResponseEvent $event) use ($output, $self) {
    echo "Received payload response:\n";
    var_dump($event->getRawPayloadResponse()); // array containing the data that was returned by Slack
});

// ...

$apiClient->send($payload); // will trigger both events sequentially

This example is taken from the Slack CLI package.