DEV Community

Cover image for Octwilio - combining the Octopus and Twilio APIs for #TwilioHackathon
Ryan Rousseau for Octopus Deploy

Posted on • Updated on

Octwilio - combining the Octopus and Twilio APIs for #TwilioHackathon

"Building something with the Twilio API" has been on my to-do list for a while now. When I saw the Twilio x DEV hackathon announcement, it sounded like the best time to check that item off my list.

Specifically, I have wanted to put something together using the Octopus and Twilio APIs. I will journal my progress here on DEV. I have set this up as a series, so new posts should be linked together as I write them. Let's get to work on Octwilio! I love a good portmanteau.

Main Goal

You can add manual approval steps to your deployment process in Octopus. They look like this:

A manual intervention waiting for approval in the Octopus UI

You can provide some notes and then proceed with the deployment or cancel it after taking responsibility for the approval.

A manual intervention assigned to you

Priority number one for Octwilio is to receive a text when there is approval required. Then the receiver should be able to approve the deployment by replying to the message.

Stretch Goals

Once I get the main goal finished, I have other ideas that I will tackle with the remaining time.

  • A method to configure different numbers to message based on the Octopus project, environment, etc.
  • Messages for when deployments start, complete, or fail.
  • Initiating deployments by text message.
  • Maybe a web UI to manage the configuration.

Plan

Octwilio will be a start as a group of cloud functions that call each of the APIs. Events from Octopus will trigger API calls to send messages from a Twilio number. Messages to the Twilio number will spawn API calls to Octopus.

I will probably use Firebase to host the cloud functions. Twilio can also host functions, so that is another option to explore.

Getting Started

Before I started on feature one, I did some testing with the Twilio API to see how to use it. I logged into my trial account and found the account tokens needed for the API.

It did not take long to find a PowerShell example of sending an SMS with Twilio.

With just a little modification, I can plug this logic into an Octopus Deploy step template.

$url = "https://api.twilio.com/2010-04-01/Accounts/$Twilio_SendMessage_AccountSID/Messages.json"
$params = @{
    To = $Twilio_SendMessage_ToNumber;
    From = $Twilio_SendMessage_FromNumber;
    Body = $Twilio_SendMessage_Message
}

Write-Verbose "Creating Twilio credentials"
$secureToken = $Twilio_SendMessage_AuthToken | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($Twilio_SendMessage_AccountSID, $secureToken)

Write-Verbose "Creating Twilio credentials"
Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing
Enter fullscreen mode Exit fullscreen mode

The values $Twilio_SendMessage_AccountSID, $Twilio_SendMessage_AuthToken, $Twilio_SendMessage_ToNumber, $Twilio_SendMessage_FromNumber, and $Twilio_SendMessage_Message are provided through parameters to the step template. I can add this step to my process and provide the values into the step form:

Twilio - Send Message step form

And after deploying a release using this step, I received this message:

Text message from Octopus

I published the step template to the Octopus Deploy Community Library. You can import the step template into your instance and use it in your processes.

This step template is not part of Octwilio, but it was easy to add to the library, so I will call that a lagniappe.

Up next

I created a repository for Octwilio.

GitHub logo ryanrousseau / octwilio

Octwilio is a project to combine the Octopus Deploy and Twilio APIs.



It is empty at the time of writing, but that is where the code will live. You can watch that for progress along with the blog series.

In the next post, I will create a cloud function that handles when Octopus requires approval.

Cover photo by Qijin Xu on Unsplash.

Top comments (0)