Can I use JS when creating a Slack message?

So when creating a Slack message the app says that I can use Templates but only mentions {{Name}}. Can I use Javascript <%= name %> as well? It doesn’t seem to work.

Would be great to have clarity (and consistency) here, as well as a clear documentation.

Welp, @Polina_Zenevich and @ChrisG. Thanks!

I think unfortunately that the slack message action doesn’t support JS, unlike some other markdown actions, but maybe @Oleg will confirm

1 Like

Yeah, that’s the impression I had based on it being a different input component… which surprised me as I would have hoped that these functionalities behave the same across it all.

But I guess this is a case of things being more complicated under the hood. :wink:

Hi!
I think that has to be possible
There is a reference in the documentation, can it be helpful?

1 Like

Hi, @njyo

It is possible to access fields of entity by using <%= Entity.Name %>. Please note: fields are not fulfilled by default, so additional instruction or additional call may be required.

Thanks,
Oleg

2 Likes

Thanks, @Polina_Zenevich and @Oleg. So yes, it’s definitely possible. The different input component and lack of description/help text with it surely confuses. → Please fix. :slightly_smiling_face:

Here my working script (for posterity):

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

TEST: :white_check_mark: *{= Environments:Name =} downtime scheduled* in {= Countries:Flag,CA3 Code =} from <%= e['Time Window']['Start'].slice(0,10) %> at <%= e['Time Window']['Start'].slice(11,16) %> to <%= e['Time Window']['End'].slice(0,10) %> at <%= e['Time Window']['End'].slice(11,16) %> UTC.

Feels odd to mix it all together, but it seems to work. :wink:

On a different note, I find the documentation around how to access entities and their values in JS rather confusing. Is there a simple primer somewhere? → please fix

For example, searching in the docs for getEntityById yields some code, but no explanation of the function: What is Entity.Type and Entity.Id, are they required? I know the last two items are the ones I want to load:

	 const e = await fibery.getEntityById(Entity.Type, Entity.Id, ['Time Window'],['Description']);

Seems like documents use some kind of Secret… not sure why? Doing this does not seem to work:

<%
	const fibery = context.getService('fibery');
	const e = await fibery.getEntityById(Entity.Type, Entity.Id, ['Time Window'],['Description']);
	const desc = "";
	if (e['Description']) {
		  const desc = await fibery.getDocumentContent(e['Description'].secret, 'md').slice(0,50);
	}
%>

:white_check_mark: *{= Environments:Name =} downtime scheduled*
<%= desc %>

Again, not sure how fibery.getDocumentContent works or why I need it, but it seems to work in the examples given…

As said, thanks a lot for helping with this, I can pretty much do, what I wanted. But at the same time, a clean primer on entities and and using hem in MD and JS would be neat. Thanks!

Looking at this specifically:
https://the.fibery.io/search/lKqbY#User_Guide/Guide/Markdown-Templates-53

  1. Using entity fields:
    1. How can I list all the fields available in an entity?
    2. What are the default fields always present in an entity?
    3. Why is the syntax here and in formulae different? Very confusing that formulae, MD and JS all use different syntax it seems
  2. Hidden initialization
    1. Cool. But what does this mean? How do I use it?
    2. Overall, for these three shortcuts it would just be nice to list what output they generate too. :slightly_smiling_face: Especially as the comma-separated list has no space… so for UI purposes probably not that useful → ability to extend with custom separator string?
  3. Collection → Table formatting
    1. The intro talks about a document but the example shows a comment. I guess comments are also documents, but that wording is confusing.
    2. Also, maybe better to say: using this code [code] yields a result like this [screenshot of comment]. You can do this by setting up a button [screenshot of button automation]
  4. More complex formatting
    1. I suspect that my custom separators in a list is exactly this… but without a display of the result, I would have to test myself.
  5. Using Entities and Users
    1. And now the tutorial just breach light-speed: New syntax, new concepts of UUID of entity and user… can I link to them? What does it return? There is a raw example, not sure what that means, etc.
    2. I suspect that this would allow me to link to items from Slack, but again, it’s just VERY terse…

… and so on.

Hope this explains why I have all these questions and I think a bit of cleanup and expansion on this would empower a lot of us. :pray:

1 Like