def smardigoUrl = "https://" + envManagementHostname + "/api/redirect/process/" + contextScopeId + "/dossier/" + process_definition_key + "/" + execution.getProcessInstanceId()
def smardigoMessageUrl = "https://" + envManagementHostname + "/api/v1/scopes/" + contextScopeId + "/processes/" + execution.getProcessInstanceId() + "/messages"

def message = [:]
message["@type"] = "MessageCard"
message["@context"] = "http://schema.org/extensions"
message["themeColor"] = "0076D7"
message["summary"] = "Neue Aufgabe: " + "Mein comment"

def section = [:]
section["activityTitle"] = activityTitle
section["activitySubtitle"] = activitySubtitle
section["activityImage"] = "https://www.netgo.de/wp-content/uploads/2022/10/weiss_icon_rakete-33-80x80.png"
section["facts"] = [
  [name:"Stage",value:envStage],
  [name:"Mandant",value:tenant.name]
]
message.sections = [section]

def potentialAction = []

def openInSmardigo = [:]
openInSmardigo["@type"] = "ViewAction"
openInSmardigo["@context"] = "http://schema.org"
openInSmardigo["name"] = "Vorgang öffnen"
openInSmardigo["target"] = [smardigoUrl]
potentialAction.add(openInSmardigo)

if (vorgang_status > 1000) {
  def approveInSmardigo = [:]
  approveInSmardigo["@type"] = "HttpPOST"
  approveInSmardigo["name"] = "Server freigeben"
  approveInSmardigo["target"] = smardigoMessageUrl
  approveInSmardigo["body"] = "{\"message\":\"process-approved-" + execution.getProcessInstanceId() + "\"}"
  approveInSmardigo["headers"] = [
    [name:"Smardigo-User-Token",value:envSmardigoUserToken]
  ]
  potentialAction.add(approveInSmardigo)
}

message.potentialAction = potentialAction

message