Getting started to use Plivo in Github Actions

GitHub Actions simplify automating all of your software activities, including CI/CD. You can build, test, and deploy code directly from GitHub. You can use GitHub Actions with Plivo to send SMS messages right from your GitHub workflow, which means you can notify people about the actions you performed on the repository.

Get a Phone number

Before you get started, you must have an SMS-enabled Plivo phone number to send SMS messages to numbers in the US and Canada. You can purchase numbers from the Phone Numbers page of the console, or by using the Numbers API.

Buy a New Plivo Number

Configuring credentials

You also need to know your Plivo Auth ID and Auth Token, which you can find on the overview screen of the Plivo console.

Find Your Auth Credentials on Plivo Console

But you don’t want to put your authentication credentials or other private information into your YAML file. If you’re working in a public repository, the YAML file is exposed to everyone, so your secrets would be exposed too.

Fortunately, GitHub has a way to keep this information secret. Go to your repository’s settings and select Secrets from the left menu bar. s

Add the secrets related to your project in this section. Once you’ve put them up, you won’t be able to read them in the UI. Instead, you access them through notation like ${{secrets.SECRET_NAME}}.

Create these secrets for this workflow:

  • PLIVO_AUTH_ID : A Plivo Auth ID which can be found in console
  • PLIVO_AUTH_TOKEN : A Plivo Auth Token which can be found in console
  • FROM_NUMBER : Phone number in your Plivo account to send the SMS from.
  • TO_NUMBER : Phone number to send the SMS to

Note: Secret names are case-sensitive.

Set up your workflow

In GitHub Actions, a workflow is a configurable automated process made up of one or more jobs. A YAML file defines your workflow configuration.

You can use the GitHub web UI to add a workflow to your repository, or you can configure your workflow by modifying files locally. Here’s how each of those processes look.

GitHub UI

  • Go to the repository where you want to set up a workflow.
  • Click on Actions, then select set up a workflow. Set up worklflow
  • Under Marketplace, search for Plivo SMS, then click on it. Github Marketplace
  • Copy the code snippet from the Installation pane and paste it into your main.yml file.
  • You can paste the code snippet within the steps interface.
steps: 
- name: 'Sending SMS Notification'
  uses: plivo/actions-sms@v1
  with:
    fromPhoneNumber: ${{secrets.FROM_NUMBER}}
    toPhoneNumber: ${{secrets.TO_NUMBER}}
    message: '💡There has been new release to ${{github.repository}}'
  env:
    PLIVO_AUTH_ID: ${{secrets.PLIVO_AUTH_ID}}
    PLIVO_AUTH_TOKEN: ${{secrets.PLIVO_AUTH_TOKEN}}
  • Click on the Start commit button to commit the changes in your branch.

Locally

  • Go to your local repository and create a new directory named .github/workflows, then create a new file name main.yml.
  • Paste this code within the steps interface.
steps:
- name: 'Sending SMS Notification'
  uses: plivo/actions-sms@v1
  with:
    fromPhoneNumber: ${{secrets.FROM_NUMBER}}
    toPhoneNumber: ${{ secrets.TO_NUMBER}}
    message: '💡There has been new release to ${{github.repository}}'
  env:
    PLIVO_AUTH_ID: ${{ secrets.PLIVO_AUTH_ID}}
    PLIVO_AUTH_TOKEN: ${{ secrets.PLIVO_AUTH_TOKEN}}
  • Commit the changes to your repository.

Example: The finished YAML file

Now you’re ready to write the code to send out an SMS message every time you make a new push to the main branch of your repository. Your final main.yml file should look like this. The comments in the file explain all of the directives to use.

# This is a basic workflow to help you get started with Actions
name: Send SMS
# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      # Runs a set of commands using the runners shell
      - name: Plivo SMS
        uses: plivo/actions-sms@v1
        with:
          # Phone number in your Plivo account to send the SMS from
          fromPhoneNumber: ${{secrets.FROM_NUMBER}}
          # Phone number to send the SMS to
          toPhoneNumber: ${{secrets.TO_NUMBER}}
          # The message you want to send
          message: ‘💡There has been new release to ${{github.repository}}’
        env:
          # A Plivo auth_id. Can alternatively be stored in environment
          PLIVO_AUTH_ID: ${{ secrets.PLIVO_AUTH_ID}}
          # A Plivo auth_token. Can alternatively be stored in environment
          PLIVO_AUTH_TOKEN: ${{ secrets.PLIVO_AUTH_TOKEN}}

As a developer, you’re probably quite busy and may not take a close look at new builds or deployments. You might not be aware when someone uploads an update or submits a pull request against a repository. Now you can stay up to date no matter where you are by adding SMS notifications to your GitHub workflow.