Skip to content

Commit

Permalink
MARP-259 Mattermost Connector (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
phhung-axonivy authored Jun 5, 2024
1 parent eb99ee4 commit 0bbf7ae
Show file tree
Hide file tree
Showing 82 changed files with 2,146 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

"YOUR SHORT DESCRIPTION GOES HERE"

Read our [documentation](MY-PRODUCT-NAME-product/README.md).
Read our [documentation](MY-PRODUCT-NAME-product/README.md).
6 changes: 6 additions & 0 deletions mattermost-connector-demo/config/roles.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<role>
<identifier>Everybody</identifier>
<role>
<identifier>Leader</identifier>
</role>
<role>
<identifier>Member</identifier>
</role>
</role>
17 changes: 16 additions & 1 deletion mattermost-connector-demo/config/users.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<userConfig/>
<userConfig>
<user>
<username>leader</username>
<password>leader</password>
<fullName>Leader</fullName>
<emailAddress>[email protected]</emailAddress>
<role>Leader</role>
</user>
<user>
<username>member</username>
<password>member</password>
<fullName>Member</fullName>
<emailAddress>[email protected]</emailAddress>
<role>Member</role>
</user>
</userConfig>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Data #class
com.axonivy.connector.mattermost.connector.demo #namespace
result List<com.your.mattermost.url.client.ChannelMember> #field
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MattermostConnectorWebhookDemoData #class
com.axonivy.connector.mattermost.connector.demo #namespace
message String #field
message PERSISTENT #fieldModifier
channelId String #field
channelId PERSISTENT #fieldModifier
15 changes: 15 additions & 0 deletions mattermost-connector-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@
<version>${project.version}</version>
<type>iar</type>
</dependency>
<dependency>
<groupId>com.axonivy.connector.mattermost</groupId>
<artifactId>mattermost-connector-notification</artifactId>
<version>${project.version}</version>
<type>iar</type>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>maven.axonivy.com</id>
<url>https://maven.axonivy.com</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"format" : "10.0.0",
"id" : "18F952928A1574A7",
"config" : {
"data" : "com.axonivy.connector.mattermost.connector.demo.MattermostConnectorWebhookDemoData"
},
"elements" : [ {
"id" : "f0",
"type" : "SignalStartEvent",
"name" : "Check Team Absences",
"config" : {
"signalCode" : "CheckTeamAbsences",
"output" : {
"map" : {
"out.channelId" : "signal.getSignalData() as String"
},
"code" : [
"import com.axonivy.connector.mattermost.enums.CustomField;",
"ivy.case.customFields().stringField(CustomField.CHANNEL_ID.getFieldName()).set(out.channelId);"
]
},
"attachToBusinessCase" : "false",
"tags" : "demo"
},
"visual" : {
"at" : { "x" : 104, "y" : 112 },
"labelOffset" : { "x" : 17, "y" : -23 }
},
"connect" : { "id" : "f3", "to" : "f2" }
}, {
"id" : "f1",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 784, "y" : 112 }
}
}, {
"id" : "f2",
"type" : "TaskSwitchEvent",
"name" : "Check team absences",
"config" : {
"task" : {
"name" : "Check Team Absences",
"responsible" : {
"role" : "Leader"
}
}
},
"visual" : {
"at" : { "x" : 232, "y" : 112 },
"labelOffset" : { "x" : 14, "y" : 34 }
},
"connect" : { "id" : "f6", "to" : "f5" }
}, {
"id" : "f5",
"type" : "DialogCall",
"name" : "TeamAbsences",
"config" : {
"dialogId" : "com.axonivy.connector.mattermost.connector.demo.TeamAbsences",
"startMethod" : "start()",
"output" : {
"map" : {
"out" : "in",
"out.message" : "result.message"
}
}
},
"visual" : {
"at" : { "x" : 360, "y" : 112 }
},
"connect" : { "id" : "f17", "to" : "f16" }
}, {
"id" : "f7",
"type" : "Script",
"name" : "Send message to channel",
"config" : {
"output" : {
"code" : [
"import com.axonivy.connector.mattermost.bo.IncomingWebhookParameter;",
"import com.axonivy.connector.mattermost.demo.service.MattermostWebhookService;",
"MattermostWebhookService service = new MattermostWebhookService();",
"service.sendMessageToMattermostChannel(in.channelId, \"Absence Summary: \" + in.message);"
]
}
},
"visual" : {
"at" : { "x" : 648, "y" : 112 }
},
"connect" : { "id" : "f4", "to" : "f1" }
}, {
"id" : "f16",
"type" : "TaskSwitchEvent",
"name" : "Send message to channel",
"config" : {
"task" : {
"name" : "Send message to channel",
"responsible" : {
"role" : "SYSTEM"
}
}
},
"visual" : {
"at" : { "x" : 504, "y" : 112 },
"labelOffset" : { "x" : 14, "y" : 34 }
},
"connect" : { "id" : "f8", "to" : "f7" }
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.axonivy.connector.mattermost.demo.service;

import javax.annotation.security.PermitAll;
import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.apache.commons.lang.StringUtils;

import com.axonivy.connector.mattermost.bo.SlashCommandGetRequestParameter;
import com.axonivy.connector.mattermost.bo.SlashCommandResponse;
import com.fasterxml.jackson.databind.ObjectMapper;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.process.model.value.SignalCode;

@Path("/mattermost/slashCommand")
@PermitAll
public class MattermostSlashCommandService {
@GET
public String startProcess(@BeanParam SlashCommandGetRequestParameter parameter) {
SlashCommandResponse response = new SlashCommandResponse();
response.setResponseType("in_channel");
response.setText(String.format("Process CheckTeamAbsences has been started by %s", parameter.getUserName()));
Ivy.wf().signals().send(new SignalCode("CheckTeamAbsences"), parameter.getChannelId());
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(response);
} catch (Exception e) {
e.printStackTrace();
return StringUtils.EMPTY;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.axonivy.connector.mattermost.demo.service;

import org.apache.commons.lang.StringUtils;

import com.axonivy.connector.mattermost.bo.IncomingWebhookParameter;
import com.axonivy.connector.mattermost.service.ChannelService;
import com.axonivy.connector.mattermost.service.IncomingWebhookService;
import com.axonivy.connector.mattermost.service.TeamService;
import com.your.mattermost.url.client.Channel;
import com.your.mattermost.url.client.IncomingWebhook;

import ch.ivyteam.ivy.environment.Ivy;

public class MattermostWebhookService {
public MattermostWebhookService() {
}

public void sendMessageToMattermostChannel(String channelId, String message) {
String teamId = TeamService.getTeamIdByTeamName(Ivy.var().get("mattermost.teamName"));
if (StringUtils.isBlank(teamId)) {
return;
}

IncomingWebhook webhook = IncomingWebhookService.getIncommingWebhookId(channelId, teamId);
if (webhook == null || StringUtils.isBlank(webhook.getId())) {
return;
}

Channel channel = ChannelService.getChannelById(channelId);
if (channel == null || StringUtils.isBlank(channel.getId())) {
return;
}

sendIncomingWebhook(channel, webhook.getId(), message);
}

private void sendIncomingWebhook(Channel channel, String webhookId, String message) {
try {
IncomingWebhookParameter parameter = new IncomingWebhookParameter(channel.getName(), message);
IncomingWebhookService.sendIncomingWebhook(parameter, webhookId);
} catch (Exception ex) {
Ivy.log().error("Failed to notify channel Id {0}: {1}", channel.getId(), ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<richDialogDescriptor>
<property>
<name>viewTechnology</name>
<value>JSF</value>
</property>
</richDialogDescriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ic="http://ivyteam.ch/jsf/component" xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:body>
<ui:composition template="/layouts/frame-10.xhtml">
<ui:define name="title">Team Absences</ui:define>
<ui:define name="content">

<h3>
Report team absences
</h3>

<h:form id="form">
<p:messages />
<h:inputTextarea value="#{data.message}"></h:inputTextarea>
<br />
<div class="command-btns">
<p:commandLink id="cancel" actionListener="#{ivyWorkflowView.cancel()}" process="@this" value="Cancel" />
<p:commandButton id="proceed" actionListener="#{logic.close}" value="Proceed" update="form" icon="pi pi-check" />
</div>
</h:form>

</ui:define>
</ui:composition>
</h:body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TeamAbsencesData #class
com.axonivy.connector.mattermost.connector.demo.TeamAbsences #namespace
message String #field
message PERSISTENT #fieldModifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"format" : "10.0.0",
"id" : "18F953D50A711458",
"kind" : "HTML_DIALOG",
"config" : {
"data" : "com.axonivy.connector.mattermost.connector.demo.TeamAbsences.TeamAbsencesData"
},
"elements" : [ {
"id" : "f0",
"type" : "HtmlDialogStart",
"name" : "start()",
"config" : {
"callSignature" : "start",
"result" : {
"params" : [
{ "name" : "message", "type" : "String" }
],
"map" : {
"result.message" : "in.message"
}
},
"guid" : "18F953D50A7ED10A"
},
"visual" : {
"at" : { "x" : 96, "y" : 64 }
},
"connect" : { "id" : "f2", "to" : "f1" }
}, {
"id" : "f1",
"type" : "HtmlDialogEnd",
"visual" : {
"at" : { "x" : 224, "y" : 64 }
}
}, {
"id" : "f3",
"type" : "HtmlDialogEventStart",
"name" : "close",
"config" : {
"guid" : "18F953D50A9D7F2B"
},
"visual" : {
"at" : { "x" : 96, "y" : 160 }
},
"connect" : { "id" : "f5", "to" : "f4" }
}, {
"id" : "f4",
"type" : "HtmlDialogExit",
"visual" : {
"at" : { "x" : 224, "y" : 160 }
}
} ]
}
Loading

0 comments on commit 0bbf7ae

Please sign in to comment.