Search in sources :

Example 1 with ErrorResponse

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

the class ChatWorkflowErrorHandler method handleError.

@Override
public void handleError(Throwable t) {
    LOG.error("Error thrown:", t);
    Action currentAction = Action.CURRENT_ACTION.get();
    if (currentAction != null) {
        ErrorResponse er = new ErrorResponse(currentAction.getAddressable(), t, templateName);
        try {
            rh.accept(er);
        } catch (Throwable e) {
            LOG.warn("Couldn't return error {} due to error {} ", er, e);
        }
    }
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Example 2 with ErrorResponse

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

the class WebHookOps method template.

@Exposed(description = "Change the template used by the last called webhook", addToHelp = true, isButton = true, isMessage = true)
public static Response template(SymphonyHistory hist, Addressable a, Workflow wf) {
    Optional<EntityJson> ej = hist.getLastEntityJsonFromHistory(ActiveWebHooks.class, a);
    if (ej.isEmpty()) {
        return new ErrorResponse(wf, a, "No webhooks defined");
    }
    Optional<WebHook> activeHook = hist.getFromEntityJson(ej.get(), WebHook.class);
    if (activeHook.isEmpty()) {
        return new ErrorResponse(wf, a, "Active Hook not set");
    }
    Template t = activeHook.get().getTemplate();
    ButtonList bl = new ButtonList();
    bl.add(new Button(TEMPLATE_UPDATE, Type.ACTION, "Update Template"));
    return new FormResponse(wf, a, ej.get(), "Template Edit", "Update the template used by " + activeHook.get().getDisplayName(), t, true, bl);
}
Also used : FormResponse(org.finos.symphony.toolkit.workflow.response.FormResponse) EntityJson(org.finos.symphony.toolkit.json.EntityJson) Button(org.finos.symphony.toolkit.workflow.form.Button) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse) Exposed(org.finos.symphony.toolkit.workflow.java.Exposed)

Example 3 with ErrorResponse

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

the class WebHookOps method newhook.

@Exposed(addToHelp = true, isButton = false, description = "Create a New Webhook receiver. e.g.  <b>/newhook #somesubjecthashtag Your Hook Title</b>", isMessage = true)
public static ActiveWebHooks newhook(Workflow wf, HashTag ht, Message m, Helpers h, Room r, Addressable a, SymphonyRooms sr, SymphonyHistory hist, ResponseHandler rh) {
    ActiveWebHooks webhooks = hist.getLastFromHistory(ActiveWebHooks.class, a).orElse(new ActiveWebHooks());
    String display = m.without(Word.of("newhook")).without(Word.of("/newhook")).only(Word.class).stream().map(w -> w.getText() + " ").reduce("", String::concat).trim();
    String hookId = h.createHookId(ht.getName(), display);
    for (WebHook w : webhooks.getWebhooks()) {
        if (w.getHashTag().equals(ht)) {
            rh.accept(new ErrorResponse(wf, a, "A webhook with this tag already exists: " + ht.getId()));
            return webhooks;
        }
    }
    String streamId = r == null ? sr.getStreamFor(a) : sr.getStreamFor(r);
    String url = h.createHookUrl(streamId, hookId);
    WebHook out = new WebHook();
    out.setDisplayName(display);
    out.setHookId(new HashTagDef(hookId));
    out.setHashTag(ht);
    out.setUrl(url);
    webhooks.getWebhooks().add(out);
    return webhooks;
}
Also used : HashTagDef(org.finos.symphony.toolkit.workflow.content.HashTagDef) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse) Exposed(org.finos.symphony.toolkit.workflow.java.Exposed)

Example 4 with ErrorResponse

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

the class Scheduler method handleFeed.

public void handleFeed(Addressable a) {
    try {
        Optional<ReminderList> fl = h.getLastFromHistory(ReminderList.class, a);
        if (fl.isPresent()) {
            ReminderList updatedList = new ReminderList(fl.get());
            ZoneId zone = updatedList.getTimeZone();
            Instant currentTime = LocalDateTime.now().toInstant(ZoneOffset.UTC);
            ZoneOffset zo = zone.getRules().getOffset(currentTime);
            fl.get().getReminders().stream().forEach((currentReminder) -> {
                Instant timeForReminder = currentReminder.getLocalTime().toInstant(zo);
                if (timeForReminder.isBefore(currentTime)) {
                    Map<String, Object> ej = WorkResponse.createEntityMap(currentReminder, null, null);
                    updatedList.getReminders().remove(currentReminder);
                    ej.put("ReminderList", updatedList);
                    WorkResponse wr = new WorkResponse(a, ej, "display-reminder", WorkMode.VIEW, Reminder.class);
                    responseHandlers.accept(wr);
                }
            });
        }
    } catch (Exception e) {
        responseHandlers.accept(new ErrorResponse(a, e));
    }
}
Also used : ZoneId(java.time.ZoneId) Instant(java.time.Instant) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ReminderList(org.finos.symphony.toolkit.tools.reminders.ReminderList) ZoneOffset(java.time.ZoneOffset) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Example 5 with ErrorResponse

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

Aggregations

ErrorResponse (org.finos.symphony.toolkit.workflow.response.ErrorResponse)7 EntityJson (org.finos.symphony.toolkit.json.EntityJson)2 Exposed (org.finos.symphony.toolkit.workflow.java.Exposed)2 MessageResponse (org.finos.symphony.toolkit.workflow.response.MessageResponse)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1 Feed (org.finos.symphony.rssbot.feed.Feed)1 ReminderList (org.finos.symphony.toolkit.tools.reminders.ReminderList)1 Action (org.finos.symphony.toolkit.workflow.actions.Action)1 HashTagDef (org.finos.symphony.toolkit.workflow.content.HashTagDef)1 Button (org.finos.symphony.toolkit.workflow.form.Button)1 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)1 FormResponse (org.finos.symphony.toolkit.workflow.response.FormResponse)1 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)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 WebhookPayload (org.finos.symphony.webhookbot.domain.WebhookPayload)1