Octwilio - combining the Octopus and Twilio APIs for #TwilioHackathon
Tags: devops, twilio, octopus, twiliohackathon
Published: 2020-04-16 13:02:21

---
title: Octwilio - combining the Octopus and Twilio APIs for #TwilioHackathon
published: true
description: Let's connect Octopus Deploy and Twilio for #TwilioHackathon.
tags: devops,twilio,octopus,twiliohackathon
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/7l78qfdaj4tvmi5v7ve3.jpg
series: Building Octwilio
---

"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](https://dev-to-uploads.s3.amazonaws.com/i/wc66cc6c3jyklhccdw4h.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/u0lrhtin9kyw5ef9px14.png)

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](https://www.twilio.com/docs/usage/tutorials/how-to-make-http-basic-request-twilio-powershell) of sending an SMS with Twilio.

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

```powershell
$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
```

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](https://dev-to-uploads.s3.amazonaws.com/i/fgrjdc9vdq49347htzl4.png)

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

![Text message from Octopus](https://dev-to-uploads.s3.amazonaws.com/i/xz4zjx021m77fjqmhjb6.png)

I published the step template to the [Octopus Deploy Community Library](https://library.octopus.com/step-templates/3c3904a9-d08c-4f18-b86c-0304800bb541/actiontemplate-twilio-send-sms-(powershell)). 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](https://www.merriam-webster.com/dictionary/lagniappe).

## Up next

I created a repository for Octwilio.
{% github ryanrousseau/octwilio no-readme %}
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](https://unsplash.com/@obkim) on [Unsplash](https://unsplash.com/)._