Howto write an ChatCommand

Tl;Dr

Provide an antony registry ( https://diegroupware.atlassian.net/wiki/spaces/ant2/pages/1558642697) , let it be load and register an IChatCommand to be displayed within the chat.

General

Antony offers the possibility to provide a IChatCommand which will be displayed within a chat. You can use this to let you integrate within some systems. As an example well show how to provide these commands by the ZoomModule.

As you can see a custom “Zoom Meeting erzeugen” Button appears within the RibbonBar of the chat. On Click our Module communicates with the ZoomApi to create an instant meeting. The JoinUri, MeetingId and Password is sent as a message into the chat. In additional the user retrieve a chat hint with the uri to start the meeting.

1. Registry

To let you integrate into antony you need to provide a registry (see https://diegroupware.atlassian.net/wiki/spaces/ant2/pages/1558642697). If done correctly you can register your ZoomCreateMeetingCommand into antony’s IServiceCollection. As the chat comes up your ZoomCreateMeetingCommand is loaded.

[assembly: AntonyModule(typeof(ZoomModuleAntonyRegistry), "edef747c-e370-40d8-89c4-2f032a6b3314", RegistryGroup = "")] namespace antony.Groupware.AddinX.Zoom { public class ZoomModuleAntonyRegistry { [AntonyServiceRegistry()] public void Register(IServiceCollection services) { // some more here services.AddTransient<IChatCommand, ZoomCreateMeetingCommand>(); } } }

2. ZoomCreateMeetingCommand

You need to provide some informations so that your command is displayed. You can see an example in the code below. This code is only an trimmed example to focus the ChatCommands aspect only.

As you can see the ZoomCreateMeetingCommand is an IChatCommand from the https://www.nuget.org/packages/antony.Groupware.ExtensionInterfaces/ NuGet-Package. You need to provide an AntonyCommandInfo object. This information is used to “design” your button. You will see, that this type is reused within the IFlexObjectCommand and IContactCommand.

We’ll only provide you a way to display an image as SVG ( ). As Svg is scalable we’ll can make sure the icon is rendered sharp.

In the constructor of the class you see that an IAttachedChatService is injected into our class. This service can be used to interact with the chat. In our ZoomModule well send the message and the hint with this service. Also we’ll retrieve the title of the chat here.

public class ZoomCreateMeetingCommand : IChatCommand { public AntonyCommandInfo ActionInfo => new AntonyCommandInfo { DisplayName = "Zoom Meeting erstellen", GroupName = "Zoom", ImageAsSvg = Resources.zoom, PageName = "" }; public event EventHandler CommandStateChanged; public IAttachedChatService _attachedChatService { get; set; } public ZoomCreateMeetingCommand(IZoomApiClient zoomApiClient, IAttachedChatService attachedChatService) { _attachedChatService = attachedChatService; } public ZoomCreateMeetingCommand(IZoomApiClient zoomApiClient, IAttachedChatService attachedChatService) { _zoomApiClient = zoomApiClient; ActionInfo = new AntonyCommandInfo { DisplayName = "Zoom Meeting erstellen", GroupName = "Zoom", ImageAsSvg = Resources.zoom, PageName = "" }; _attachedChatService = attachedChatService; } public CommandState GetCommandState() => CommandState.Normal; public async Task ExecuteAsync(IntPtr parentWindow, IProgressReporter reporter) { } }

We’ll also provide a method to let your button be invisible or grayed out with the possibility to change this, if neccessary. Antony updates the state of the button in some cases. Like within WPF itself its some kind of magic here.

The last method is the point of interest here- The ExecuteAsync Method is called as the user clicks on your button. You’ll get two parameters here. First an IntPtr to the Chat’s window. This pointer can be used to display another form with a correct set parent. This way you can provide the windows behaviour of modal windows the correct way.

The second parameter can be used to report some progress to the antuser. For example you can report some messages, which might be interessting. You also can report a progress, which will be display as a progressbar. The IProgressReporter can also be used to Log your progress. Your logs will be present in the antony logs.

In the current Version (2.21.130) of antony the messages within the IProgressReporter aren’t displayed to the antuser. But in further versions of antony these informations might be displayed. So don’t write some crap in it

Conclusion

As you saw it is right simple to provide a custom button within the chat. You can use this method to create some easy but powerfull integrations. Perhaps you want to search for an ordner within an ERP system to put some detail informations to the chat. Perhaps you want to create a message with ticket details to be dispartcher.