helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Support hydrating embedded threads in incoming webhooks #289

Closed matt-h closed 8 months ago

matt-h commented 2 years ago

This pulls the code from https://github.com/helpscout/helpscout-api-php/pull/208

It keeps just the hydrating embedded threads part of that pull request while removing the part that added withEmbed to conversation filters.

I'm pulling this back up because when getting webhooks with the IncomingWebhook class the threads are all embedded in the request, but it is impossible to access them since they are never hydrated.

The only thing that might be missing here is getting the correct value for ->getThreadCount().

Currently the webhooks I'm getting are setting threads to 1 which in this code:

if (is_numeric($data['threads'])) {
     $this->setThreadCount($data['threads']);
}

Sets it to that. I'm not sure if embedded threads should do anything to change that without knowing how the underlying system works so I'll leave that up to you if that needs to be modified more. This change doesn't change that at all from how it currently works anyway. And this change allows me to use ->getThreads() which is the goal of what I'm trying to do with this.