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

API & Webhooks Module: missing some events? #4141

Closed
MacPrawn opened this issue Jul 22, 2024 · 11 comments
Closed

API & Webhooks Module: missing some events? #4141

MacPrawn opened this issue Jul 22, 2024 · 11 comments

Comments

@MacPrawn
Copy link

Hi all!

I'm trying to connect a FreeScout installation to a custom remote application via the API. It seems there may be some events that are not sent out by the API, and I was wondering if there's a reason for the omissions or if they are just things to be added, in which case I offer to submit a PR:

  1. If I select conversations from a folder's list (i.e. "Unassigned", "Mine", etc) and then bulk delete all conversations, the API does not send a "convo.deleted" message for any of the deleted conversations. If I go in each conversation individually and click the "Trash" button, that works.
  2. Restoring a deleted message does not seem to issue an event? I would expect either a specific "Restore" event? Or at the very least a "conversation.moved" event?
  3. When a message is permanently deleted (i.e. not just placed in the "Deleted" folder) there is no event sent out?

Thanks!

@freescout-help
Copy link
Collaborator

  1. Fixed in the master branch and will be published in the next release.

  2. It's by design. Feel free to submit a feature request.

  3. It's by design. Feel free to submit a feature request.

@MacPrawn
Copy link
Author

Thankl you for your prompt response. Would you mind if I coded #2 and #3 and submitted PRs for them?

@freescout-help
Copy link
Collaborator

Yes, feel free to submit PRs.

@freescout-help
Copy link
Collaborator

"convo.deleted_forever" and "convo.restored" events have been added in API & Webhooks Module v1.0.80. There was no need in extra hooks.

@MacPrawn
Copy link
Author

Thank you but I would argue the event you are using for "convo.deleted_forever" could cause problem: the event "conversation.deleting" is called before the conversation is deleted. So if something goes wrong after that call and the conversation ends-up not being deleted in Freescout, third-party apps will potentially already have deleted their data on their end and will be left out of sync.

Is there any way to have an event fire after the conversation has successfully been deleted?

@freescout-help
Copy link
Collaborator

Normally conversations are deleted forever via https://github.com/freescout-help-desk/freescout/blob/dist/app/Conversation.php#L1889

Conversation observer's deleted() event is not fired in such cases. The module uses conversations.before_delete_forever event. The conversation.deleting event is used as backup in case the conversation is not deleted via standard $conversation->deleteForever() function.

@MacPrawn
Copy link
Author

Right, ok I see: because you use mass deletion on conversations on https://github.com/freescout-help-desk/freescout/blob/dist/app/Conversation.php#L1916

Ok, but my point still remains the same: a third-party can only be told that Freescout intends to delete one or more conversations. (through the "conversation.deleting" or "conversations.before_delete_forever" events) There's no way to know that those conversations actually have bene deleted for real and so if something goes wrong after you issued your webhook, you may end up not deleting your copy of one or more conversations and the third-party will have already deleted their copy...

At the very least, could we add a "conversations.after_delete_forever" after
https://github.com/freescout-help-desk/freescout/blob/dist/app/Conversation.php#L1918
Then you use that new event to issue your API module's "convo.deleted_forever" webhook?

It's not perfect, but at least there's less risk of getting de-synchronized...?

@freescout-help
Copy link
Collaborator

At the very least, could we add a "conversations.after_delete_forever" after
https://github.com/freescout-help-desk/freescout/blob/dist/app/Conversation.php#L1918
Then you use that new event to issue your API module's "convo.deleted_forever" webhook?

Unfortunately not. Conversation::deleteConversationsForever() deletes conversations without fetching them from DB for performance reasons, so there is no way to pass $conversation object to conversations.after_delete_forever hook.

@MacPrawn
Copy link
Author

Of course - but like your conversations.before_delete_forever event, you could pass the conversation IDs...

@freescout-help
Copy link
Collaborator

After a conversation is deleted from DB it can't be retrieved from DB by ID to pass it's data to the webhook.

@MacPrawn
Copy link
Author

:) But you already have the ids - you have them in the $conversation_ids variable...

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

No branches or pull requests

2 participants