DEV Community

Play Button Pause Button
Brian Douglas for GitHub

Posted on • Updated on

Sending PR notifications through SMS and GitHub Actions

GitHub Actions thrive thanks to its ecosystem of community actions. In that community, you will find several open-sourced actions from solo developers looking to improve their workflows, but amongst those actions, you will find a number of your popular developer tools with actions in the marketplace.

GitHub Marketplace is a new way to discover and purchase tools that extend your workflow. Learn how you can publish your Action to Marketplace.

GitHub logo twilio-labs / actions-sms

Send an SMS through GitHub Actions

Twilio SMS GitHub Action

Send an SMS from GitHub Actions.

Prerequisites

Usage

  1. Set up your credentials as secrets in your repository settings using TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET

  2. Add the following to your workflow

- name: 'Sending SMS Notification'
  uses: twilio-labs/actions-sms@v1
  with
    fromPhoneNumber: '+1(234)5678901'
    toPhoneNumber: '+1(234)3334444'
    message: 'Hello from Twilio'
  env:
    TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
    TWILIO_API_KEY: ${{ secrets.TWILIO_API_KEY }}
    TWILIO_API_SECRET: ${{ secrets.TWILIO_API_SECRET }}
Enter fullscreen mode Exit fullscreen mode

Inputs

fromPhoneNumber

Required Phone number in your Twilio account to send the SMS from

toPhoneNumber

Required Phone number to send the SMS to

message

Required The message you want to send

TWILIO_ACCOUNT_SID

A Twilio Account SID. Can alternatively be stored in environment

TWILIO_API_KEY

A Twilio API Key. Can alternatively be stored in environment

TWILIO_API_SECRET

A Twilio…

To begin, you will need a GitHub Actions workflow YAML. I copied mine directly from the twilio-labs/actions-sms. The Twilio team maintains the action from an open-source repo, so if you have questions or looking for other features, definitely reach out to them there.

name: PR text MSG
on: [pull_request]
jobs:
  text:
    runs-on: ubuntu-latest
    steps:
    - name: 'Sending SMS Notification'
      uses: twilio-labs/actions-sms@v1
      with:
        fromPhoneNumber: '+1(267)8282212'
        toPhoneNumber: ${{ secrets.PAGER_NUMBER }}
        message: 'Hello from Twilio'
      env:
        TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
        TWILIO_API_KEY: ${{ secrets.TWILIO_API_KEY }}
        TWILIO_API_SECRET: ${{ secrets.TWILIO_API_SECRET }}
Enter fullscreen mode Exit fullscreen mode

Something to keep in mind is that you will need a Twilio trial account and create a Programmable Messaging service to generate your secret key and SID. If you are also curious about how to set up secrets in a GitHub rep, check out my previous article on The Secrets of An Authenticated GitHub Action Workflow
. You will want to put the PAGER_NUMBER in a secret too.

Finally, set sending phone numbers to the one generated in Twilio. Also, to trigger the action I have it set to pull_request, but for testing, purposes you can also set it as workflow_dispatch.

And that is it. Enjoy your new text messages.

example of my message sent

This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev. Learn how to build action with Node.js

Latest comments (0)