bossenti commented on code in PR #2248:
URL: https://github.com/apache/streampipes/pull/2248#discussion_r1410746527


##########
streampipes-extensions/streampipes-sinks-notifications-jvm/src/main/java/org/apache/streampipes/sinks/notifications/jvm/msteams/MSTeamsSink.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.sinks.notifications.jvm.msteams;
+
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import 
org.apache.streampipes.extensions.api.pe.context.EventSinkRuntimeContext;
+import org.apache.streampipes.model.DataSinkType;
+import org.apache.streampipes.model.graph.DataSinkDescription;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.pe.shared.PlaceholderExtractor;
+import org.apache.streampipes.sdk.StaticProperties;
+import org.apache.streampipes.sdk.builder.DataSinkBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+import org.apache.streampipes.sdk.helpers.Alternatives;
+import org.apache.streampipes.sdk.helpers.EpRequirements;
+import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.wrapper.params.compat.SinkParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataSink;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClients;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class MSTeamsSink extends StreamPipesDataSink {
+
+  private static final String KEY_MESSAGE_ADVANCED = "messageAdvanced";
+  private static final String KEY_MESSAGE_ADVANCED_CONTENT = 
"messageContentAdvanced";
+  private static final String KEY_MESSAGE_SIMPLE = "messageSimple";
+  private static final String KEY_MESSAGE_SIMPLE_CONTENT = 
"messageContentSimple";
+  private static final String KEY_MESSAGE_TYPE_ALTERNATIVES = "messageType";
+  private static final String KEY_WEBHOOK_URL = "webhookUrl";
+  protected static final String SIMPLE_MESSAGE_TEMPLATE = "{\"text\": \"%s\"}";
+
+  private String messageContent;
+  private boolean isSimpleMessageMode;
+  private String webhookUrl;
+
+  @Override
+  public void onEvent(Event event) {
+
+    // This sink allows to use placeholders for event properties when defining 
the message content in the UI
+    // Therefore, we need to replace these placeholders based on the actual 
event before actually sending the message
+    var processedMessageContent = 
PlaceholderExtractor.replacePlaceholders(event, messageContent);
+
+    String teamsMessageContent;
+    if (isSimpleMessageMode) {
+      teamsMessageContent = 
createMessageFromSimpleContent(processedMessageContent);
+    } else {
+      try {
+        teamsMessageContent = 
createMessageFromAdvancedContent(processedMessageContent);
+      } catch (JsonProcessingException e) {
+        throw new RuntimeException(
+                "Advanced message content provided is not a valid JSON string: 
%s"
+                        .formatted(messageContent)
+        );
+      }
+    }
+
+    try {
+      sendPayloadToWebhook(HttpClients.createDefault(), teamsMessageContent, 
webhookUrl);

Review Comment:
   https://media.giphy.com/media/K0Hy2NwI8IXZK/giphy.gif



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to