en-us/Pick_up_the_Phone_with_Pipeworks.walkthru.help.txt
<#
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](http://twilio.com) 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" -ItemType Directory -ErrorAction SilentlyContinue -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" { function Request-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 -Name SmtpEmail -ValueOnly $smtpPassword = Get-SecureSetting -Name SmtpPassword -ValueOnly $smtpCred = New-Object Management.Automation.PSCredential ".\$smtpEmail", (ConvertTo-SecureString -AsPlainText -Force $smtpPassword) if ($Message -like "http*") { Send-MailMessage -To info@company.com -From info@company.com -Body (Write-Link -Url $Message -Caption "Listen To Message") -BodyAsHtml -Subject "Message From $From" -UseSsl -Credential $smtpCred -SmtpServer smtp.outlook.com } else { Send-MailMessage -To info@company.com -From info@company.com -Body $Message -Subject "Message From $From" -UseSsl -Credential $smtpCred -SmtpServer smtp.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-Module GetBack -Force -PassThru | ConvertTo-ModuleService -Force -Do "/Request-Information" -AsIntranetSite -Port 1919 <# 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](http://www.twilio.com/docs/api/twiml/twilio_request) 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](http://www.twilio.com/docs/api/twiml/say) verb. If that string starts with http, Twilio will Play it with the [Play verb](http://www.twilio.com/docs/api/twiml/play). If the result could be XML, it will return the result inside of the TwilML. #> |