Last active
February 23, 2026 17:44
-
-
Save mark05e/7527778ad45916a219e73132340777b8 to your computer and use it in GitHub Desktop.
TSIP CLI Tool - A command-line interface for the tSIP VoIP softphone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| TSIP CLI Tool - A command-line interface for the tSIP VoIP softphone. | |
| .DESCRIPTION | |
| Automates tSIP via its SCRIPT_B64 interface. Supports dialing, sending DTMF, | |
| and displaying messages. Includes a built-in contact manager (contacts.csv). | |
| .PARAMETER DefaultInput | |
| Sends DTMF tones by default if no switch is provided. (Position 0) | |
| .PARAMETER ContactList (-cl) | |
| Lists all saved contacts. | |
| .PARAMETER ContactAdd (-ca) | |
| Adds a new contact. Usage: -ca "Name,Number" | |
| .PARAMETER Call (-c) | |
| Initiates a call. Accepts a raw number or a shortcode from contacts.csv. | |
| .PARAMETER Dtmf (-d) | |
| Sends DTMF tones. Accepts raw digits (0-9, *, #) or a shortcode from contacts.csv. | |
| .PARAMETER ShowMessage (-s) | |
| Displays a popup message within the tSIP interface. | |
| .PARAMETER Hangup (-h) | |
| Terminates the current active call. | |
| .EXAMPLE | |
| .\tsip-cli 1234# | |
| Sends DTMF tones directly. | |
| .EXAMPLE | |
| .\tsip-cli -c mom | |
| Looks up 'mom' in contacts.csv and dials the number. | |
| .EXAMPLE | |
| .\tsip-cli -ca "office,5551234" | |
| Adds a new contact to the address book. | |
| .EXAMPLE | |
| .\tsip-cli -h | |
| Hangs up the current call. | |
| .LINK | |
| Project Home: https://gist.github.com/mark05e/7527778ad45916a219e73132340777b8 | |
| .LINK | |
| tSIP Official Documentation: https://tomeko.net/software/SIPclient/ | |
| .LINK | |
| tSIP Scripting Reference: https://tomeko.net/software/SIPclient/scripting/ | |
| #> | |
| param ( | |
| [Parameter(Position=0)] | |
| [string]$DefaultInput, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("d")] | |
| [string]$Dtmf, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("c")] | |
| [string]$Call, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("s")] | |
| [string]$ShowMessage, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("cl")] | |
| [switch]$ContactList, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("ca")] | |
| [string]$ContactAdd, | |
| [Parameter(Mandatory=$false)] | |
| [Alias("h")] | |
| [switch]$Hangup | |
| ) | |
| # --- Configuration --- | |
| $exePath = "C:\MarkTools\tsip\tsip.exe" | |
| $csvPath = "$PSScriptRoot\contacts.csv" | |
| # --- Helper: Ensure CSV exists --- | |
| function Initialize-Contacts { | |
| if (-not (Test-Path $csvPath)) { | |
| "Name,Number" | Out-File $csvPath -Encoding UTF8 | |
| } | |
| } | |
| # --- Helper: Lookup Shortcode --- | |
| function Get-ContactValue ([string]$InputVal) { | |
| if ($InputVal -match '[a-zA-Z]') { | |
| if (Test-Path $csvPath) { | |
| $match = Import-Csv $csvPath | Where-Object { $_.Name -eq $InputVal } | |
| if ($match) { return $match.Number } | |
| } | |
| Write-Host "Error: Shortcode '$InputVal' not found in contacts.csv" -ForegroundColor Red | |
| exit 1 | |
| } | |
| return $InputVal | |
| } | |
| # --- 1. Handle Contact Management --- | |
| Initialize-Contacts | |
| if ($ContactList) { | |
| Write-Host "`n--- TSIP Contact List ---" -ForegroundColor Cyan | |
| $data = Import-Csv $csvPath | |
| if ($data) { | |
| $data | Format-Table -AutoSize | |
| } else { | |
| Write-Host "Contact list is empty." -ForegroundColor Gray | |
| } | |
| exit 0 | |
| } | |
| if ($ContactAdd) { | |
| if ($ContactAdd -notmatch ",") { | |
| Write-Host "Error: Entry must be in `"Name,Number`" format (found: $ContactAdd)." -ForegroundColor Red | |
| exit 1 | |
| } | |
| $ContactAdd | Out-File $csvPath -Append -Encoding UTF8 | |
| Write-Host "Contact added successfully: $ContactAdd" -ForegroundColor Green | |
| exit 0 | |
| } | |
| # --- 2. Determine Action --- | |
| $actionValue = "" | |
| $actionType = "" | |
| $displayVal = "" | |
| if ($Hangup) { | |
| $actionValue = "Hangup()" | |
| $actionType = "Terminating Call" | |
| $displayVal = "Active Session" | |
| } | |
| elseif ($Call) { | |
| $val = Get-ContactValue $Call | |
| if ($val -notmatch '^\d{3,}$') { | |
| Write-Host "Error: Invalid phone number '$val'." -ForegroundColor Red; exit 1 | |
| } | |
| $actionValue = "Call(`"$val`")" | |
| $actionType = "Calling" | |
| $displayVal = if ($Call -eq $val) { $val } else { "$Call ($val)" } | |
| } | |
| elseif ($ShowMessage) { | |
| $actionValue = "ShowMessage(`"$ShowMessage`")" | |
| $actionType = "Displaying Message" | |
| $displayVal = $ShowMessage | |
| } | |
| elseif ($Dtmf -or $DefaultInput) { | |
| $rawInput = if ($Dtmf) { $Dtmf } else { $DefaultInput } | |
| $val = Get-ContactValue $rawInput | |
| if ($val -notmatch '^[0-9\*#]+$') { | |
| Write-Host "Error: Invalid DTMF '$val'. Use only 0-9, *, and #." -ForegroundColor Red; exit 1 | |
| } | |
| $actionValue = "SendDtmf(`"$val`")" | |
| $actionType = "Sending DTMF" | |
| $displayVal = if ($rawInput -eq $val) { $val } else { "$rawInput ($val)" } | |
| } | |
| else { | |
| Get-Help $PSCommandPath | |
| exit 0 | |
| } | |
| # --- 3. Base64 Encoding (UTF-8) --- | |
| $bytes = [System.Text.Encoding]::UTF8.GetBytes($actionValue) | |
| $base64 = [Convert]::ToBase64String($bytes) | |
| # --- 4. Execution --- | |
| if (-not (Test-Path $exePath)) { | |
| Write-Host "Error: tsip.exe not found at $exePath" -ForegroundColor Red | |
| exit 1 | |
| } | |
| $argument = "/tsip=SCRIPT_B64=$base64" | |
| Write-Host "${actionType}: $displayVal" -ForegroundColor Green | |
| Start-Process -FilePath $exePath -ArgumentList $argument |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment