Wondering how others check for params in command

I am updating a workflow that I built a little while ago that lets some people reset passwords in AD. Our process has been updated that for some instances we have to notify a person’s manager when we reset their password.

Our workflow is kicked off via MS Teams using

!reset-password <sam/upn>

I plan on adding two parameters: -notify and -ticket

I know I could just require having them in a specific order, but I know some people will keep forgetting.

So, question is, instead of looping the words property through a loop and checking each item value to see if these two values exist, is there a better way to determine if those two parameters were included in the trigger? Should I just dump the value of the trigger.words to an artifact and then run the artifact through a regex action?

The end goal would look something like this:

!reset-password -notify -ticket <ticket#> <sam/upn>

or

!reset-password <sam/upn> -notify -ticket <ticket#>

This is the same workflow that is used for account clean up so the list could be rather long, which is why I want to avoid having to loop through an entire array.

Thanks!
Sean

*Edit: added what the command would look like with the parameters sent via Teams

It’s a good idea for users to follow the same format for executing the workflow each time and also to notify them when parameters are in the wrong order. It would then be best to extract those using the pattern match step using the variable feature. It would then look something like this:

Input: message
Pattern: !reset-password -notify {{notify: /.*/}} -ticket {{ticket:/.*/}}

Docs: Use a Pattern Match Step | InsightConnect Documentation

I do this all the time, but with pattern matching.
My initial Regex is (?i)^!reset-?password
I then have a pattern match of
-t(icket)?(=|:|\s)“?{{TicketNumber:/[^\s”]+/}}

On catch, make sure you run the remove html tags from the returned string, Teams inserts these when you copy/paste and will break your ^

I was just reading your reply to another thread that you mentioned the same thing but for trigger check.

What are you using to stop the HTML out? I have not found an action that will do that.

The problem generally arrises when users copy/paste text into the message in Teams. You can try having them “paste without formatting.” To paste text without formatting on both Mac and Windows, use Ctrl + Shift + V on Windows and Cmd + Shift + V on Mac. Otherwise, you can use the HTML plugin to strip the HTML from the text before running the message through pattern match.

1 Like

I cannot trust people to paste correctly so I use the HTML plugin like suggested, this will slow down the workflow slightly but saves you from people reaching out saying that isn’t working. I also try to account for the different ways that people might enter the argument to avoid human error

1 Like

If you want to control how people enter the command and give them a GUI like interface, look into adaptive cards. I have that trigger on the ICON username, it presents a simple GUI where they copy and paste into that form, it then formats the command correctly. This allows you to manually enter the command (e.g. have another Workflow post a command for you, we use this when a Workflow wants to automatically reset a password, instead of the Workflow calling it, it sends the Teams command) or a user can use the GUI

1 Like

What? I have never heard of this feature. My primary function is not automation, it is more like, “do it when you never, i mean have, time.”

So they would log into InsightConnect to run the commands? I will look into this. Thank you!

Thank you for the input on the HTML plugin. I will look into this! I did not see this response.

I am trying to do that right now and it sort of feels like an effort in futility. Every time I think I have it figured out, they figure out something new and novel to cause a problem. lol.

This is not an ICON feature, it is a Teams feature. But I use it because people cannot remember the different commands
https://learn.microsoft.com/en-us/power-automate/overview-adaptive-cards

1 Like

I had to make assumptions on your user names and your ticket format, but assuming your usernames do not contain numbers, and your tickets do contain numbers, with JQ you can make your workflow work. I tested with the following scenarios and everyone of them works.

!reset-password -notify -ticket 1351351346 darrick
!reset-password -notify darrick -ticket 1351351346
!reset-password -ticket 1351351346 -notify darrick
!reset-password -ticket 1351351346 darrick -notify
!reset-password darrick -notify -ticket 1351351346
!reset-password darrick -ticket 1351351346 -notify

!reset-password -ticket 1351351346 darrick
!reset-password -ticket 1351351346 darrick
!reset-password darrick -ticket 1351351346

Below is a workflow you can import and test it out if you want.

The JQ statement looks like this:

.message.words as $words
| {
notify: ($words | index(“-notify”) | if . == null then false else true end),
ticket: (
$words
| map(select(type == “string” and test(“\d”)))
| .[0]
),
user: (
$words
| map(select(
type == “string”
and (test(“^!”) | not)
and (test(“^-[a-zA-Z]+$”) | not)
and (test(“\d”) | not)
))
| .[0]
)
}

I am returning a true or a false if the notify flag was sent through. You can just leverage a decision on that variable.

Handle Non Standard User Input.icon (33.4 KB)

1 Like