Search in sources :

Example 1 with HashTagDef

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

Aggregations

HashTagDef (org.finos.symphony.toolkit.workflow.content.HashTagDef)1 Exposed (org.finos.symphony.toolkit.workflow.java.Exposed)1 ErrorResponse (org.finos.symphony.toolkit.workflow.response.ErrorResponse)1