Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple events #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add support for multiple events #26

wants to merge 4 commits into from

Conversation

hotmeteor
Copy link
Owner

This PR adds support for handling multiple events in a single payload.

The getEvent method has been updated to support the return of either a string or array value, and the handle method updated accordingly.

Resolves #13

@jeffreyvanhees
Copy link

jeffreyvanhees commented Oct 19, 2023

Good PR! The only thing I am missing is that in my case the data is also different per event. Maybe you could pass the event name in the getData-method so I can figure out how to fetch the data from that specific event?

{
    "time_ms": 1697717045179,
    "events": [
        {
            "name": "channel_occupied",
            "channel": "admin",
            "data": {} <---
        },
        {
            "name": "member_added",
            "channel": "admin",
            "data": {} <---
        }
    ]
}
public function getData(Request $request, string $event): array
{
    return $request->collect('events')
        ->filter(fn($item) => $item['name'] === $event)
        ->map(fn($item) => $item['data'])
        ->toArray();
}

@hotmeteor
Copy link
Owner Author

@jeffreyvanhees Did you grab the latest version? Maybe run composer update and try again, I made that change as well.

@hotmeteor
Copy link
Owner Author

@jeffreyvanhees
Copy link

jeffreyvanhees commented Oct 19, 2023

As far as I know I have the latest version. ("hotmeteor/receiver": "dev-multi-events"). Did you test it with the JSON from the example?

I get the error Cannot assign array to property Receiver\AbstractWebhook::$event of type ?string in

$this->{$key} = $value;
when I post the JSON from the example.

Also, can you give an example how to use the getData()-method in this case?

Note: in the new example you'd add to the readme, you use $this->request instead of the $request-argument. Is there a reason for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple events in single request
2 participants