Search by

itsmurumba / laravel-otp

ItsMurumba

Laravel Package for sending otps via SMS, Email, Slack

Package info

github.com/ItsMurumba/laravel-otp

pkg:composer/itsmurumba/laravel-otp

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.1-rc.1 2026-09-12 12:30 UTC

This package is auto-updated.

Last update: 2026-09-15 15:40:41 UTC


README

A flexible and feature-rich Laravel package for generating and sending One-Time Passwords (OTP) through multiple channels including Email, SMS, WhatsApp, Telegram, and Slack.

Features

  • 📱 Multiple delivery channels (Email, SMS, WhatsApp, Telegram, Slack)
  • 🔢 Configurable OTP formats (numeric, alphanumeric)
  • ⏱️ Customizable expiration time
  • 🔄 Easy channel switching
  • ✅ Channel-specific validation
  • 🛠️ Extensible architecture

Requirements

  • PHP 8.1 or higher
  • Laravel 10, 11, 12, or 13 (CI is tested against 12 and 13)

Installation

You can install the package via composer:

composer require itsmurumba/laravel-otp

After installation, publish the configuration file:

php artisan vendor:publish --provider="Itsmurumba\Otp\OtpServiceProvider"

Configuration

Copy the required environment variables from .env.example to your .env file and configure them according to your needs:

cp .env.example .env

The package supports the following channels, each requiring specific configurations:

Email

  • Requires Laravel mail settings
  • Uses standard Laravel mail configuration

SMS

  • Requires SMS API credentials
  • Configure SMS_API_KEY and SMS_API_URL

WhatsApp

  • Requires WhatsApp Business API credentials
  • Configure WHATSAPP_API_KEY and WHATSAPP_API_URL

Telegram

  • Requires Telegram Bot Token
  • Configure TELEGRAM_BOT_TOKEN

Slack

  • Requires Slack Webhook URL
  • Configure SLACK_WEBHOOK_URL

Usage

Basic Usage

use Itsmurumba\Otp\Facades\Otp;

// Generate and send an OTP (defaults to the "sms" channel)
$otp = Otp::generateAndSend('recipient@example.com', 'email');

// Verify an OTP
$isValid = Otp::verify('recipient@example.com', $otp);

You can also resolve the underlying service directly instead of the facade (via the otp() helper or the otp container binding):

$otpService = otp(); // same as app('otp')

$otp = $otpService->length(6)
    ->expiresIn(10)
    ->rateLimit(3, 15)
    ->generateAndSend('recipient@example.com', 'email');

$isValid = $otpService->verify('recipient@example.com', $otp);

Channel-Specific Usage

Email

use Itsmurumba\Otp\Channels\EmailChannel;

$channel = new EmailChannel();
$result = $channel->send('user@example.com', '123456');

SMS

use Itsmurumba\Otp\Channels\SmsChannel;

$channel = new SmsChannel();
$result = $channel->send('+1234567890', '123456');

WhatsApp

use Itsmurumba\Otp\Channels\WhatsAppChannel;

$channel = new WhatsAppChannel();
$result = $channel->send('+1234567890', '123456');

Telegram

use Itsmurumba\Otp\Channels\TelegramChannel;

$channel = new TelegramChannel();
$result = $channel->send('chat_id', '123456');

Slack

use Itsmurumba\Otp\Channels\SlackChannel;

$channel = new SlackChannel();
$result = $channel->send('#channel-name', '123456');

Sending via Multiple Channels

Pass an array of channel names to send the same OTP through more than one channel:

$otp = $otpService->generateAndSend('+1234567890', ['sms', 'whatsapp']);

OTP Verification

$isValid = $otpService->verify('+1234567890', $otp);

verify() checks the code against the stored, non-expired, unverified OTP for that identifier and marks it as verified on success.

Testing

composer test

To run the test suite with code coverage (requires Xdebug or PCOV):

composer test:coverage

Security

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

Credits

License

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