<?xml version="1.0" encoding="utf-8"?>
<AlvaoApplication xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ModelVersion="1">
  <Applications>
    <Application id="51">
      <Name>Ticket Create Outlook Meeting</Name>
      <Description>To the Request page, adds the “Create meeting” command that creates a new meeting in the MS Outlook calendar.</Description>
      <UniqueId>a50c61d0-71e8-4b82-b04f-c673b4db43b2</UniqueId>
      <Version>2</Version>
      <AdvancedSettings />
      <Scripts>
        <Script id="207">
          <Name>TicketCreateOutlookMeetingCommand</Name>
          <Code>// Last update: 20.6.2025 16:00.
using System;
using Alvao.API.Common;
using Alvao.API.Common.Model.CustomApps;
using Alvao.Apps.API;
using Alvao.API.Common.Model.Database;
using MessageType = Alvao.API.Common.Model.CustomApps.MessageType;

public class TicketCreateOutlookMeetingCommand : IEntityCommand
{
    public string Id { get; set; }
    public Entity Entity { get; set; }

    public TicketCreateOutlookMeetingCommand()
    {
        Id = "TicketCreateOutlookMeeting".GetHashCode().ToString();
        Entity = Entity.Request;
    }

    public EntityCommandShowResult Show(int entityId, int personId)
    {
        int position = 3;
        string icon = "calendar_ltr_20_regular";
        string name = "Create meeting";
        bool show = false;
        
        tHdTicket ticket = Alvao.API.SD.Ticket.GetById(entityId);

        if (ticket != null &amp;&amp; ticket.liHdTicketHdSectionId &gt; 0)
        {
            var teamRoles = PersonRights.TicketRoles.SectionManager | PersonRights.TicketRoles.SectionMainSolver | PersonRights.TicketRoles.SectionSolver;
            show = PersonRights.HaveTicketRole(personId, entityId, ticket.liHdTicketHdSectionId, teamRoles, true);

            if (!show)
            {
                var person = Person.GetById(personId);
                if (person.sPersonEmail != null)
                    show = person.sPersonEmail.Contains("@alvao.com");
            }
        }

        return new EntityCommandShowResult(show, name, icon, position);
    }

    public CommandResult Run(int entityId, int personId)
    {
        MessageType messageType = MessageType.None;
        string messageText = string.Empty;
        string navigateToUrl = string.Empty;

        try
        {
            var userMail = Person.GetById(personId).sPersonEmail;

            if (!string.IsNullOrEmpty(userMail))
            {
                // Get ticket info
                var waUrl = DbProperty.WebAppUrl;
                var ticket = Alvao.API.SD.Ticket.GetById(entityId);
                var ticketFullName = $"{ticket.sHdTicket} ({ticket.sHdTicketMessageTag})";
                var body = "";
                if (!string.IsNullOrEmpty(waUrl))
                {
                    body = $"&lt;a href=\"{waUrl}/Ticket/{entityId}\"&gt;{ticket.sHdTicketMessageTag}&lt;/a&gt;";
                    body += "&lt;/br&gt;";
                    body += $"&lt;a href=\"{waUrl}/Act/New?ticketId={entityId}&amp;type=2\"&gt;Report time&lt;/a&gt;";
                }

                navigateToUrl = "https://outlook.office.com/calendar/deeplink/compose?subject=" + System.Net.WebUtility.UrlEncode(ticketFullName) + "&amp;body=" + System.Net.WebUtility.UrlEncode(body);
            }
        }
        catch (Exception e)
        {
            messageType = MessageType.Error;
            messageText = e.Message;
            return new CommandResult(messageType, messageText, navigateToUrl);
        }

        return new CommandResult(messageType, messageText, navigateToUrl);
    }
}</Code>
          <IsLibCode>false</IsLibCode>
          <Codesign>fiLsOnP3Vw5XAnuCnUCrFAf3tDLPRYGoZppd3xulFLW03pL+QByeH79ikaH30dKOg8QnjOVvqgIbk0j2y2fmCGd1lSJ/Gwck5rW39l7kePA4wk63Cvr1KZ+tW4tDe4//K6GopDSAbLeDA1ez+swkY1mkaLtnTUJw+lTfkklhx6RUT/xpgQKkoD3BdtGKAb/O/wZszn+mjwoewVlIcd05guTdLVQ3/+54Hh9QzIlpDfpfAnZVF1rxLclYzo7fDS1W50bZF5imqljufHFu6t/n49Ly6XM7UdvQVFxhwvPFF8tPKbAXKCMVaNGvlHsE3hp/szk/KSiMH9DLZ70dDqoF3Q==</Codesign>
        </Script>
      </Scripts>
    </Application>
  </Applications>
</AlvaoApplication>