use of org.finos.symphony.webhookbot.domain.Template in project spring-bot by finos.
the class ReceiveController method receiveWebhook.
@PostMapping(path = "/hook/{streamId}/{hookId}")
public ResponseEntity<Void> receiveWebhook(@PathVariable(name = "streamId") String streamId, @PathVariable(name = "hookId") String hookId, @RequestBody JsonNode body) throws JsonProcessingException {
Room r = rooms.loadRoomById(streamId);
ActiveWebHooks ho = history.getLastFromHistory(ActiveWebHooks.class, r).orElse(new ActiveWebHooks());
WebHook hook = getHook(ho, hookId);
if ((hook != null) && (hook.isActive())) {
// ok, we've found the webhook for this call.
Template template = hook.getTemplate();
if (template == null) {
template = createDefaultTemplate(body, hook.getDisplayName());
hook.setTemplate(template);
}
EntityJson out = createEntityJson(body, ho, hook);
MessageResponse mr = new MessageResponse(wf, r, out, "", "", template.getContents());
handler.accept(mr);
return new ResponseEntity<Void>(HttpStatus.OK);
}
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
use of org.finos.symphony.webhookbot.domain.Template in project spring-bot by finos.
the class ReceiveController method createDefaultTemplate.
private Template createDefaultTemplate(JsonNode body, String title) {
List<String> fields = new ArrayList<String>();
String prefix = "entity.payload.contents";
addSomeFields(prefix, body, fields);
String fieldsTemplate = fields.stream().map(n -> "\n<tr><td><span class=\"tempo-text-color--secondary\">" + n.substring(prefix.length()) + "</span></td>\n" + "<td><span class=\"tempo-bg-color--red tempo-text-color--white tempo-token\">${" + n + "}</span></td></tr>\n").reduce("", String::concat);
Template out = new Template();
out.setName(title + " Default Template");
out.setContents("<table>" + fieldsTemplate + "</table>" + buttonForm());
out.setShared(false);
return out;
}
use of org.finos.symphony.webhookbot.domain.Template in project spring-bot by finos.
the class UpdateTemplateConsumer method apply.
@Override
public List<Response> apply(ElementsAction t) {
if (t.getAction().equals(WebHookOps.TEMPLATE_UPDATE)) {
try {
Template template = (Template) t.getFormData();
EntityJson workflow = t.getData();
ActiveWebHooks awh = (ActiveWebHooks) workflow.get(EntityJsonConverter.WORKFLOW_001);
WebHook active = (WebHook) workflow.get(ReceiveController.INVOKED_WEBHOOK);
WebHook wh = ReceiveController.getHook(awh, active.getHookId().getId());
wh.setTemplate(template);
WebhookPayload payload = (WebhookPayload) workflow.get(ReceiveController.PAYLOAD);
EntityJson out = ReceiveController.createEntityJson(payload.getContents(), awh, wh);
MessageResponse mr = new MessageResponse(t.getWorkflow(), t.getAddressable(), out, "", "", template.getContents());
return Collections.singletonList(mr);
} catch (JsonProcessingException e) {
return Collections.singletonList(new ErrorResponse(t.getWorkflow(), t.getAddressable(), e.getMessage()));
}
} else {
return Collections.emptyList();
}
}
Aggregations