I'm finding Templates confusing

I’m trying to set up incident management in Fibery to integrate with Slack. I would like that when an incident is created, a dedicated Slack channel is created for that incident and posted to another Slack channel.

The dedicated channel should be called #incident-<ID>-<name>
I’ve sort-of got this working (albeit without zero-padded months/days) using a Create Channel slack action with the following formula for the channel name:

Left("incident-" + [Step 1 Incident].[Public Id])) + "-" +
    ReplaceRegex([Step 1 Incident].Name,"[^A-Za-z0-9-]","-"), 80)

Hurrah. But now I’m trying to post a message containing that channel name to the main #incidents Slack channel and I’m getting an error: “Failed to execute Action “Send Message To Channel”: Response code 400 (Bad Request)”

Some comments:

  • It would be very helpful to provide more error context. I’ve no idea what is bad about the request.
  • I can’t figure out how to debug this.
  • The “Templates can be used (for example {{Name}} and etc.)” helper text for the action doesn’t help much. The help around this generally is confusing and a little scattered, across Markdown Templates, Rules, Automation use cases, Script, Markdown Template (again), etc.

It is very unobvious to me, from all of this, what I should be doing. {{Public Id}} works in the markdown text, but <% Entity.['Public Id'] %> gives a 400 error. <% Entity.Id %> works but isn’t what I want. I would ideally like to replicate the above Formula in the markdown, but can’t figure out how to.

It’s annoying enough that there are two completely different ways of doing this (why can’t I use formulas in the markdown?) but doubly frustrating that I cannot figure out for the life of me how to make this work. I have >20 years of professional programming and a computer science degree from Cambridge University under my belt, but after about 20 attempts at different syntax I have given up. :frowning:

A well-curated GitHub repo with a README.md that consolidates the existing docs (or links to a canonical documentation page in the manual), plus a set of example scripts would go a long way to helping resolve this, by the way.

(Help me Obi-Wan Chr1sG, you’re my only hope.)

1 Like

Oh, and I’ve just realised that you can’t actually link to the channel that is created anyway, as the Slack API needs the channel ID, not the channel name. :frowning:

I don’t suppose this is available in the template somehow for a newly-created Slack channel, is it?

In general, here’s how I would explain the use of markdown in Fibery:

Where markdown is possible, Fibery generally supports the ‘standard’ markdown functions, as described here.

Standard markdown is augmented by Fibery-specific functions that relate to dynamic content. This includes things like {{Name}} , {{Tasks:Status}} , {- Assignees:Name -} etc. and is explained in the User Guide.

If these functions are not enough, it is possible to use scripting to achieve more complex things.
Scripting uses Javascript, and when used in markdown is written within blocks that start/end with <% and %>
Within such script blocks, the Entity object is available for use (it has Type and Id properties).

Field values can be accessed in a similar way as would be done for scripting in general,

<%
    const fibery = context.getService('fibery');
    const entityWithAssignees = await fibery.getEntityById(Entity.Type, Entity.Id, ['Assignees']);
%>

Note: scripting does not itself directly generate any output, unless values are explicitly ‘pushed’ to markdown using <%= and %>
e.g. <%= entityWithAssignees.map((e) => e.Name).join(" | ") %>

In some cases, it’s simplest to combine markdown and scripting, e.g. initialise a field using markdown, and then format the resultant values using scripting:

{!Tasks:Name!} // much easier than using await fibery.getEntityById(Entity.Type, Entity.Id, ['Tasks']);
<%= Entity.Tasks.map((t) => t.Name).join(`,`) %>

I agree that debugging markdown, especially where it uses scripting, is not easy.

{{Public Id}} works because it is a field that is accessible via markdown
<% Entity.['Public Id'] %> does not work, because Entity only has the the properties Type and Id unless otherwise initialised.

I think it’s reasonable that, for most use cases at least, the Fibery-augmented markdown provides enough functionality for users without any great SW experience. It would complicate things too much if markdown supported the full complexity of javascript.

Once scripting comes into play, the possibilities are enormous, and it’s very difficult for us to provide user guides - if we tried to explain every possibility, we’d end up recreating stackoverflow(!)

2 Likes