Never Miss Notifications Using SMS Github Action
Tags: githubactions, showdev, programming
Published: 2023-03-18 16:15:46

As a software engineer and [open source](https://github.com/alphaolomi?tab=repositories) 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](https://developers.africastalking.com/docs/sms/overview) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43yo6qilyfssnoynbtg2.png)



In 2020 I participated the [GitHub Actions Hackathon](https://dev.to/alphaolomi/sms-notifications-with-action-africastalking-1c33). 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:


```yaml
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 }}`
```

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 
```yaml
message: PR \#${{ github.event.pull_request.number }} has been ${{ github.event.action }}' on ${{ github.repository }} by ${{ github.actor }}
```


### 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](https://africastalking.com/).

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mchi1ygmbyab1s2my4cv.jpeg)


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 alphaolomi/actions-africastalking %}