DEV Community

Alpha Olomi
Alpha Olomi

Posted on

Never Miss Notifications Using SMS Github Action

As a software engineer and open source enthusiast from Tanzania, I know firsthand the challenges of accessing the internet. Missing critical notifications when offline is a common problem in such scenarios. To tackle this problem, I created a Github Action that sends SMS notifications to a phone number using AfricasTalking Programmable SMS API. This action ensures that I receive notifications even when I am not online. In this blog post, I will introduce you to this action and show you how to use it.

This idea came when a project required a hot fix but I wasn't online in time and thus could take action in time. Then I though can't I set up a workflow that would send SMS notifications to a phone number whenever a pull request/issue is created. I was able to achieve this by using the AfricasTalking Programmable SMS API. I then decided to create a Github Action that would make it easier for other developers to set up SMS notifications in their workflows.

Image description

In 2020 I participated the GitHub Actions Hackathon. I made the first version of the action in the hackathon. I was able to improve the action and make it more robust by adding support for sending SMS notifications to multiple phone numbers. I am happy to announce version 2 of action is now available on Github.

The following are the steps to use the SMS notification Github Action:

Step 1: Create a .github/workflows/sms.yml file in your repository.

Step 2: Add the following content to the sms.yml file:

name: SMS Notifications
on:
  pull_request:

jobs:
  smsNotification:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: alphaolomi/actions-africastalking@main
        with:
          fromPhoneNumber: 'INFO' # or secrets.fromPhoneNumber
          toPhoneNumber: ${{ secrets.toPhoneNumber }}
          message: 'Hello World'
        env:
          AT_API_KEY: ${{ secrets.AT_API_KEY }}
          AT_USERNAME: ${{ secrets.AT_USERNAME }}`
Enter fullscreen mode Exit fullscreen mode

You can customize the message to reflect the event that triggered the workflow. For example, you can send a message that says A new pull request has been created when a pull request is created. You can also send a message that says A pull request has been merged when a pull request is merged. You can also send a message that says A pull request has been closed when a pull request is closed.

Or more advanced use cases, example

message: PR \#${{ github.event.pull_request.number }} has been ${{ github.event.action }}' on ${{ github.repository }} by ${{ github.actor }}
Enter fullscreen mode Exit fullscreen mode

Step 3: Add the following secrets to your repository:

  • AT_API_KEY - Your Africastalking API Key
  • AT_USERNAME - Your Africastalking Username

To get an API key, follow the instructions on the AfricasTalking website.

The SMS notification Github Action will send a notification message to the phone number specified in the toPhoneNumber field with the message specified in the message field. You can also specify a fromPhoneNumber field to set the phone number from which the message will be sent. If you do not want to expose your phone number, you can use the secrets.fromPhoneNumber field to specify a secret.

SMS from GH action

In conclusion, with this Github Actions, you can wire up many use cases and this is just one of them. This can be particularly useful for developers and community leaders in areas where internet access is challenging. By using AfricasTalking SMS API, you can easily set up SMS notifications in your workflow. The SMS notification Github Action is available on Github, and I encourage you to give it a try.

GitHub logo alphaolomi / actions-africastalking

Send an SMS from GitHub Actions using Africastalking Programmable SMS

📨 Africastalking SMS Action

A GitHub Action to send a text message to mobile number of choice using Africastalking Programmable SMS

Usage

  1. Create a .github/workflows/sms.yml file in your repository.
  2. Add the following content to the sms.yml file:
name: SMS Notification
on:
  pull_request:

jobs:
  smsNotification:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: alphaolomi/actions-africastalking@main
        with:
          fromPhoneNumber: 'INFO' # or secrets.fromPhoneNumber
          toPhoneNumber: ${{ secrets.toPhoneNumber }}
          message: 'Hello World'
        env:
          AT_API_KEY: ${{ secrets.AT_API_KEY }}
          AT_USERNAME: ${{ secrets.AT_USERNAME }}
Enter fullscreen mode Exit fullscreen mode
  1. Add the following secrets to your repository:
  • AT_API_KEY - Your Africastalking API Key
  • AT_USERNAME - Your Africastalking Username

Inputs

  • AT_API_KEY Required. You can get this from the Africastalking's Dashboard.
  • AT_USERNAME Required. Use 'sandbox' as the value for development in the test environment
  • fromPhoneNumber Required. The name or number the message will…




Top comments (0)