Link user that is mentioned in a comment


What is the solution/script to link a user to a field when the user is mentioned in a comment?

So example:

  • When a Fibery user is mentioned in a comment (within a task)
  • Then link the user to field ‘Mentioned’

(we have another use case; but this explains it simply)


You would have to

  • create an automation that runs when a comment is added
  • use a script action to
    – extract the latest comment
    – trawl the comment for mentions (using regex pattern matching)
    – link the mentioned user(s) to the entity

This assumes that you’re talking about the Comments field.

If you are talking about inline comments, it’s another story

1 Like

Yes, that’s exactly what I need but I’m struggling with the script. Can you share it with me?

Thanks again!

I recall that you already had a script that you were using to detect mentions in comments and create custom notifications, or do I misremember?
It would seem that this need is the same, but just needs modifying to link the user instead of creating a new entity.

Hi Chris,

The script that we had, fetched the mentions from the comments of a task and created a new entity in the separate notification database. That worked perfectly.

In this scenario we need to fetch the mention of the comment within the entity itself and then link the user to the correct field.

I’ve tried to adjust the script to accomplish this. But because the original was quite complex (because of the two separate databases) I need some help.

I’m not a script hero :see_no_evil:

I’m not sure what this means. Just to double check, are we talking about inline comments or the comments field?

Apologies if I’m not clear!

I’m talking about the comments field.

So example:

  • If a user is mentioned in the comment of a task
  • Then link the user that is mentioned in the comment of the task to the field ‘involved team mates’

Do you still have the previous automation script for detecting mentions? I can save myself some time if I can re-use some chunks of it :slight_smile:

Hi Chris,

After the release of the new Inbox we’ve cleaned up our ‘own notication system’ + automations/scripts :see_no_evil:.

So the exact scripts we had then are gone, but when I’ve tried to fix it myself, I’ve used the scripts that you’ve mentioned in this post. Because I don’t fully understand the script it’s hard for me to adjust it to this use case.

Ah yes, thanks for reminding me.

I think for the use case you describe above, the script needs to look something like this:

const fibery = context.getService('fibery');

function getMentions(text) {
    const regex = /(?<=\[\[#\@[a-f0-9-]+\/)[a-f0-9-]+/g;
    const found = text.match(regex);
    return found;

for (const entity of args.currentEntities) {
    const entityWithComments = await fibery.getEntityById(entity.type,, ['Comments']);
    const lastComment = entityWithComments['Comments'].pop();
    const content = await fibery.getDocumentContent(lastComment['Document secret'], 'md');
    const matches = getMentions(content);
    if (matches) {
        for (const match of matches) {
            await fibery.addCollectionItem(entity.type,, 'Mentioned', match);

You just need to add this to an automation whose trigger is ‘Entity linked to a XXX … Comments’

Awesome! Works great, thank you so much!

Maybe also a nice one to add to Fibery’s guide? It’s a quite common use case I think :smile: