Search in sources :

Example 1 with Room

use of org.finos.symphony.toolkit.workflow.content.Room 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);
}
Also used : ActiveWebHooks(org.finos.symphony.webhookbot.domain.ActiveWebHooks) ResponseEntity(org.springframework.http.ResponseEntity) EntityJson(org.finos.symphony.toolkit.json.EntityJson) MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) WebHook(org.finos.symphony.webhookbot.domain.WebHook) Room(org.finos.symphony.toolkit.workflow.content.Room) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Template(org.finos.symphony.webhookbot.domain.Template) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

EntityJson (org.finos.symphony.toolkit.json.EntityJson)1 Room (org.finos.symphony.toolkit.workflow.content.Room)1 MessageResponse (org.finos.symphony.toolkit.workflow.response.MessageResponse)1 ActiveWebHooks (org.finos.symphony.webhookbot.domain.ActiveWebHooks)1 Template (org.finos.symphony.webhookbot.domain.Template)1 WebHook (org.finos.symphony.webhookbot.domain.WebHook)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1