Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

tumainimosha/sms-sender

Repository files navigation

Sms Sender

A CLI application to send SMS from a database queue.

It uses Infobip api to send messages, thus requires you to supply a valid Infobip Username and Password.

Out of the box it works with Oracle database, but also supports:

  • PostgresSQL
  • MySQL
  • Sql Server
  • Sqlite

It can work with any database supported by a Laravel database driver.

Usage

Step 1: Clone this repository to your PC.

git clone https://github.com/tumainimosha/sms-sender.git

Step 2: Configure Environment variables

Rename the .env.example file to .env

Edit .env file and substitute your credentials

# Infobip Credentials
INFOBIP_USERNAME=infobip-user
INFOBIP_PASSWORD=infobip-pass
INFOBIP_FROM="SENDER NAME"

# Database Credentials
DB_CONNECTION=oracle
DB_HOST=10.10.0.5
DB_PORT=1521
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_SERVICE_NAME=

# Maximum number of messages sent per script run
MAX_TAKE_RUN=100

# SMS table config
TABLE_OUTGOING_SMS=outgoing_sms
COLUMN_PRIMARY_KEY=id
COLUMN_MSISDN=msisdn
COLUMN_TEXT=text
COLUMN_SENDER=sender_name
COLUMN_SENT_AT=sent_at

Step 3: Install composer dependencies

  • This step requires you to have php-7 and composer installed on your machine

  • Ensure your PHP installation has necessary database driver for database you are working with.

composer install

Step 4: Setup database table

  • Option 1: use the default table schema for messages
outgoing_sms
id PRIMARY_KEY
msisdn VARCHAR(255)
text TEXT
sender_name VARCHAR(255)
sent_at TIMESTAMP

You can create this table yourself directly on your DB

OR

use the scripts migration to create it

php sms-sender migrate
  • Option 2: use your own custom table schema for messages

If you choose to use different table name and columns from the ones specified above, edit the .env file to specify the customizations you are using

# SMS table config
TABLE_OUTGOING_SMS=outgoing_sms
COLUMN_PRIMARY_KEY=id
COLUMN_MSISDN=msisdn
COLUMN_TEXT=text
COLUMN_SENDER=sender_name
COLUMN_SENT_AT=sent_at

Step 5: Test running the script

$ php sms-sender process         
Fetch pending messages from DB: ✔
Sending messages: ✔

Step 6: Schedule the script to run at given intervals

You can schedule it using your OS's task schedule to run at given intervals, say once per minute.

It will fetch all pending messages at that time, send them, and update sent_at column to time of sending the sms.

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

About

A CLI application to send SMS from a database queue.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages