Search in sources :

Example 1 with MessageResponse

use of org.finos.symphony.toolkit.workflow.response.MessageResponse in project spring-bot by finos.

the class ClaimController method add.

@ChatButton(value = NewClaim.class, buttonText = "add")
public List<Response> add(NewClaim sc, User u, Addressable from) {
    OpenedClaim c = new OpenedClaim();
    c.amount = sc.amount;
    c.author = u;
    c.description = sc.description;
    c.status = Status.OPEN;
    Chat approvalRoom = conversations.getExistingChat("Claim Approval Room");
    return Arrays.asList(new WorkResponse(approvalRoom, c, WorkMode.VIEW), new MessageResponse(from, Message.of("Your claim has been sent to the Approval Room for processing")));
}
Also used : MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) Chat(org.finos.symphony.toolkit.workflow.content.Chat) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton)

Example 2 with MessageResponse

use of org.finos.symphony.toolkit.workflow.response.MessageResponse in project spring-bot by finos.

the class FeedController method latest.

@ChatRequest(description = "Fetch latest news now", value = "latest")
public void latest(TimedAlerter ta, History hist, Addressable a) {
    FeedList fl = getFeedList(a);
    int count = ta.allItems(a, fl);
    if (count == 0) {
        rh.accept(new MessageResponse(a, Message.of(Word.build("No New News Items"))));
    }
}
Also used : MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest)

Example 3 with MessageResponse

use of org.finos.symphony.toolkit.workflow.response.MessageResponse 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)

Example 4 with MessageResponse

use of org.finos.symphony.toolkit.workflow.response.MessageResponse in project spring-bot by finos.

the class Notifier method sendFailureNotification.

public void sendFailureNotification(SubscribeRequest sr, Addressable a, Exception e, User author) {
    rh.accept(new MessageResponse(a, "RSS Bot: Feed Creation Failed. " + properties.getFailureMessage()));
    rh.accept(new ErrorResponse(a, e));
    if (observationRoom != null) {
        rh.accept(new MessageResponse(observationRoom, "RSS Bot: New Feed Creation Failed by " + author.getName() + " Url: " + HtmlUtils.htmlEscape(sr.getUrl()) + " Room: " + a.toString()));
        rh.accept(new ErrorResponse(observationRoom, e));
    }
}
Also used : MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Example 5 with MessageResponse

use of org.finos.symphony.toolkit.workflow.response.MessageResponse 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();
    }
}
Also used : ActiveWebHooks(org.finos.symphony.webhookbot.domain.ActiveWebHooks) EntityJson(org.finos.symphony.toolkit.json.EntityJson) WebhookPayload(org.finos.symphony.webhookbot.domain.WebhookPayload) MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) WebHook(org.finos.symphony.webhookbot.domain.WebHook) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Template(org.finos.symphony.webhookbot.domain.Template) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Aggregations

MessageResponse (org.finos.symphony.toolkit.workflow.response.MessageResponse)6 EntityJson (org.finos.symphony.toolkit.json.EntityJson)2 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)2 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)2 ErrorResponse (org.finos.symphony.toolkit.workflow.response.ErrorResponse)2 ActiveWebHooks (org.finos.symphony.webhookbot.domain.ActiveWebHooks)2 Template (org.finos.symphony.webhookbot.domain.Template)2 WebHook (org.finos.symphony.webhookbot.domain.WebHook)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)1 ChatVariable (org.finos.symphony.toolkit.workflow.annotations.ChatVariable)1 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)1 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)1 Chat (org.finos.symphony.toolkit.workflow.content.Chat)1