Skip to main content

HelloID

Add, edit, or remove a PowerShell notification system
Add a PowerShell notification system (Provisioning)
  1. Go to Notifications > Systems.

    2023-06-27_14-30-21.jpg
  2. Click Add.

    2023-06-27_14-32-18.jpg
  3. Enter values for the following fields:

    Name

    A name for this PowerShell notification system. Only visible to admins.

    Icon

    An icon for this PowerShell notification system. Must be the URL of an image (beginning with https://). Only visible to admins.

    Description

    A description or note for this PowerShell notification system. Only visible to admins.

    Custom System Configuration

    Optional: Configure an input form for this PowerShell notification system. Use it to store credentials and other system-level settings.

    Execute On-Premises

    For this example, we'll enter the following values:

    2023-08-18_12-51-02.jpg
    • Name: Twilio

    • Icon: https://assets.cdn.prod.twilio.com/original_images/twilio-mark-red.png

    • Description: Send messages in Twilio.

    • Custom System Configuration: The following form:

      [
        {
          "key": "accountSid",
          "type": "input",
          "defaultValue": "",
          "templateOptions": {
            "label": "Account SID",
            "description": "Your Twilio Account SID",
            "required": true
          }
        },
        {
          "key": "authToken",
          "type": "input",
          "defaultValue": "",
          "templateOptions": {
            "label": "Auth Token",
            "description": "Your Twilio Auth Token",
            "type": "password",
            "required": true
          }
        }
      ]
      2023-08-18_12-24-12.jpg
    • Execute On-Premises: Off

  4. After entering your form JSON, click Apply.

  5. A Configuration tab is added to the system. Go to it.

    1. Enter values for the system-level variables in the input form you designed. These values will be available in the template script, via $actionContext.Configuration..

      2023-08-18_9-56-30.jpg

      For this example, we'll enter our Twilio Account SID and Auth Token values.

    2. Click Apply to save your changes.

  6. Optional: Go to the Templates tab, where you can add PowerShell notification templates for specific scenarios in this notification system.

    For this example, we'll create two templates: Twilio SMS and Twilio WhatsApp.

    2023-08-18_9-59-16.jpg
    1. Click Add to add a new template. Click its name to rename it.

      2023-08-18_12-54-46.jpg
      1. Click a template's Custom Configuration button to customize it. The template's input form should collect any variables that the script needs specifically for this scenario (as opposed to this system's input form, which, to say it again, is for general system-level variables). These values will be available in the template script via $actionContext.TemplateConfiguration..

        Important

        Each template should have a hidden and disabled field that identifies the template. This can be accomplished using the default scriptFlow variable. It should be set to "disabled": true and "hide": true.

        For this example, we'll use the following form for our Twilio SMS template:

        [
          {
            "key": "scriptFlow",
            "type": "input",
            "defaultValue": "one",
            "templateOptions": {
              "label": "Script flow",
              "disabled": true
            },
            "hide": true
          },
          {
            "key": "userName",
            "type": "input",
            "defaultValue": "{{person.UserName||\"person username\"}}",
            "templateOptions": {
              "label": "Person username",
              "disabled": true
            },
            "hide": true
          },
          {
            "key": "phoneNumber",
            "type": "input",
            "defaultValue": "{{Person.Contact.Personal.Phone.Mobile||\"person phone number\"}}",
            "templateOptions": {
              "label": "Number to send SMS to",
              "placeholder": "Please enter a phone number",
              "required": true
            }
          }
        ]
        2023-08-18_13-29-24.jpg

        And the following form for our Twilio WhatsApp template:

        [
          {
            "key": "scriptFlow",
            "type": "input",
            "defaultValue": "two",
            "templateOptions": {
              "label": "Script flow",
              "disabled": true
            },
            "hide": true
          },
          {
            "key": "userName",
            "type": "input",
            "defaultValue": "{{person.UserName||\"person username\"}}",
            "templateOptions": {
              "label": "Person username",
              "disabled": true
            },
            "hide": true
          },
          {
            "key": "whatsAppUsername",
            "type": "input",
            "defaultValue": "{{person.Custom.WhatsApp||\"person WhatsApp username\"}}",
            "templateOptions": {
              "label": "WhatsApp Username",
              "placeholder": "Please enter a WhatsApp username",
              "required": true
            }
          }
        ]
        2023-08-18_12-39-12.jpg
      2. Click Apply to save your changes.

    2. Click Configure PowerShell Script.

      1. Write the logic for your first template inside the if ($actionContext.TemplateConfiguration.scriptFlow -eq "one") block. Add additional blocks and customize the conditional logic to handle any other templates you've created, using their scriptFlow values to identify them.

      2. For this example, we'll use the following script. (We'll only include working code for the SMS template.)

        if (-Not($actionContext.DryRun -eq $true)) {
            $sid = $actionContext.Configuration.accountSid
            $token = $actionContext.Configuration.authToken
        
            if ($actionContext.TemplateConfiguration.scriptFlow -eq "one") {
                # Execute script flow one
                $number = $actionContext.TemplateConfiguration.phoneNumber
        
                $url = "https://api.twilio.com/2010-04-01/Accounts/$sid/Messages.json"
                $params = @{ To = "+1$number"; From = "+18669522556"; Body = "Hello from Template 1" }
                
                $p = $token | ConvertTo-SecureString -asPlainText -Force
                $credential = [System.Management.Automation.PSCredential]::new($sid, $p)
        
                $response = Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing | ConvertFrom-Json | Select sid, body
                Write-Information "Response: $response"
            } else {
                # Execute script flow two
                # Twilio WhatsApp call would go here
            }
        }
        
        $outputContext.AuditLogs.Add([PSCustomObject]@{
            Message = "Successfully sent a notification for person '$($actionContext.TemplateConfiguration.userName)'"
            IsError = $false
        })
        
        $outputContext.Success = $true
        2023-08-18_12-41-22.jpg
      3. Click Apply to save your changes.

Your PowerShell notification system has been added. The next step is typically to Add a notification (PowerShell) that uses this system.

  1. Go to Notifications > Systems.

  2. For the relevant PowerShell notification system, click Edit.

  3. Continue by following the instructions in Add a PowerShell notification system.

  1. Go to Notifications > Systems.

  2. For the relevant PowerShell notification system, click Edit.

  3. Click Delete.

  4. To confirm, click Delete.