1 of 2

One of the most powerful examples of what you can do in PowerShell Pipeworks is having it pick up the phone. It's a lot easier than you'd think.

The core of how PowerShell Pipeworks works is that it leverages the rich metadata in each PowerShell function to generate different experiences around that function. This means that all functions work when they are called over the phone from a Twilio number.

This example is simple and very powerful. It's a function that takes a phone call, a text message, or an web page, and sends it to an email.

Create a folder for the module

New-Item-Path"$home\Documents\WindowsPowerShell\Modules\GetBack"-ItemTypeDirectory-ErrorActionSilentlyContinue-Force|Out-Null# Create a very minimal Pipeworks manifest@'
@{
SecureSetting = 'SmtpEmail', 'SmtpPassword'
WebCommand = @{
'Request-Information' = @{
FriendlyName = 'Get In Touch'
Hidden = $true
}
}
}
'@|Set-Content"$home\Documents\WindowsPowerShell\Modules\GetBack\GetBack.pipeworks.psd1"# An a minimal module manifest@'
@{
ModuleVersion = 0.1
ModuleToProcess = 'GetBack.psm1'
}
'@|Set-Content"$home\Documents\WindowsPowerShell\Modules\GetBack\GetBack.psd1"@'
. $psScriptRoot\Request-Information.ps1
'@|Set-Content"$home\Documents\WindowsPowerShell\Modules\GetBack\GetBack.psm1"{functionRequest-Information{<#
.Synopsis
Receives phone calls, text messages, or contact info
.Description
Thank you for getting in touch.
#>param(# What can we help you with?#|LinesForInput 6#|Record[Parameter(Mandatory=$true,Position=0,ValueFromRemainingArguments=$true)][string]$Message,# Who are we helping?[Parameter(Mandatory=$true)][ValidateScript({if(-not$request["AccountSid"]){if($_-notlike"*@*.*"){throw"invalid address"}else{return$true}}else{return$true}})][string]$From)process{$smtpEmail=Get-SecureSetting-NameSmtpEmail-ValueOnly$smtpPassword=Get-SecureSetting-NameSmtpPassword-ValueOnly$smtpCred=New-ObjectManagement.Automation.PSCredential".\$smtpEmail",(ConvertTo-SecureString-AsPlainText-Force$smtpPassword)if($Message-like"http*"){Send-MailMessage-Toinfo@company.com-Frominfo@company.com-Body(Write-Link-Url$Message-Caption"Listen To Message")-BodyAsHtml-Subject"Message From $From"-UseSsl-Credential$smtpCred-SmtpServersmtp.outlook.com}else{Send-MailMessage-Toinfo@company.com-Frominfo@company.com-Body$Message-Subject"Message From $From"-UseSsl-Credential$smtpCred-SmtpServersmtp.outlook.com}"Thank you for contacting us. We will get back to you shortly."}}}|Set-Content"$home\Documents\WindowsPowerShell\Modules\GetBack\Request-Information.ps1"Import-ModuleGetBack-Force-PassThru|ConvertTo-ModuleService-Force-Do"/Request-Information"-AsIntranetSite-Port1919

2 of 2

Once that function is published to a URL, you can configure your Twilio numbers so that calls are routed to that function's URL.

Function parameters that share names with the Twilio request parameters will be automatically provided (the same is true when the handler is receiving a text message).

Positional parameters are handled in order, and the return values are converted into TwilML.

For instance, if you return a string from a function, Twilio will read it with the Say verb. If that string starts with http, Twilio will Play it with the Play verb. If the result could be XML, it will return the result inside of the TwilML.