OfficeDev / office-js-docs-reference

Microsoft Office JavaScript API Reference
https://learn.microsoft.com/javascript/api/overview
MIT License
105 stars 63 forks source link

Information on "addHandlerAsync" for "onMessageSend" in Office.js #1951

Closed CodeCube0 closed 3 weeks ago

CodeCube0 commented 3 weeks ago

Hi, i would like to know if Office.js allows adding a handler for the onMessageSend event using the addHandlerAsync function.

Thank you!

AlexJerabek commented 3 weeks ago

Hi @CodeCube0,

Thanks for the question. It looks like only ItemChanged and SelectedItemsChanged are supported by the addHandlerAsync function (source. To use onMessageSend, you'll need to follow the instructions in the Smart Alerts article.

Let me assign this to @samantharamon to confirm.

skunath commented 3 weeks ago

@AlexJerabek @samantharamon Can you confirm that the linked article actually works? I've been trying to get the onMessageSend examples to work for the past few days with no success. I've even started from scratch following the article and have not been able to get any message send alerts to work.

CodeCube0 commented 3 weeks ago

@AlexJerabek @samantharamon because I would like my add-on to capture the send event only under certain conditions

samantharamon commented 3 weeks ago

Hi @CodeCube0,

You can use addHandlerAsync for the events listed in Office.EventType. As Alex mentioned, for the OnMessageSend or OnAppointmentSend events, you must implement an event handler similar to the one in Automatically check for an attachment before a message is sent. If you'd like operations to only run when certain conditions are met, we recommend adding checks inside your event handler code. For example, in Verify the color categories of a message or appointment before it's sent using Smart Alerts, the user is only prompted to assign a color category to their mail item if specific words are included in the item's subject or body. Verify the sensitivity label of a message is another sample that implements checks in the event-handling code.

@skunath, are you referring to this tutorial: Automatically check for an attachment before a message is sent? If so, I tested it on Outlook on Windows (classic and new) and on the web and verified that the add-in works as expected. I recommend checking out Troubleshoot event-based and spam-reporting add-ins to see if it helps fix the issue. If you're still unable to run it, please open a separate GitHub issue, so that we can assist you further.

CodeCube0 commented 3 weeks ago

ok thanks I will implement a solution based on your advice @samantharamon @AlexJerabek