# Non-Masking SMS System Setup Guide

This guide explains how to set up and configure the non-masking SMS system in your Bidda project.

## What is Non-Masking SMS?

Non-masking SMS refers to SMS messages that are sent directly without any branded sender ID. Unlike masking SMS (which shows a registered brand name like "ABC_BANK"), non-masking SMS typically show the actual phone number or a generic gateway ID as the sender.

Benefits of non-masking SMS:
- Lower cost compared to masking SMS
- Faster delivery
- Suitable for internal notifications
- No need for brand registration

## Prerequisites

Before setting up non-masking SMS, ensure you have:

1. A non-masking SMS gateway provider account
2. API credentials from your SMS provider
3. Valid sender ID (if required by your provider)
4. Configured database connection

## Setup Steps

### Step 1: Database Setup

Run the setup script to create necessary tables:

```bash
php setup_non_masking_sms.php
```

This creates:
- `messages_log` table for tracking SMS delivery
- `settings` table entries for non-masking configuration

### Step 2: Configure Settings

1. Log into the Admin Panel
2. Navigate to **Admin → Non-Masking Settings**
3. Enter your SMS provider credentials:
   - API URL
   - API Key
   - Username/Password (if required)
   - Sender ID
4. Enable the non-masking messaging system
5. Save the settings

### Step 3: Test Connection

Use the test function in the settings panel to verify your API credentials are working correctly.

## Configuration Options

| Setting | Description | Default |
|---------|-------------|---------|
| Enabled | Whether non-masking SMS is active | Disabled |
| Method | Delivery method (SMS, Email, Push) | SMS |
| API URL | Your SMS provider's API endpoint | Empty |
| API Key | Authentication key for API | Empty |
| Username | Account username | Empty |
| Password | Account password | Empty |
| Sender ID | Display name/number for messages | SCHOOL |
| Rate Limit | Max messages per minute | 60 |
| Max Retries | Retry attempts for failed messages | 3 |

## Template Variables

Non-masking SMS templates support these variables:

- `{name}` - Recipient's name
- `{message}` - Main message content
- `{student_id}` - Student ID
- `{class}` - Student's class
- `{section}` - Student's section

## Sending Non-Masking SMS

### From Admin Panel

1. Go to **Admin → Send Non-Masking Message**
2. Select message type
3. Choose target group (all students, by class, or by section)
4. Write your message
5. Click "Send Message"

### Programmatically

```php
<?php
require_once('config/database.php');
require_once('includes/sms_helper.php');

// Send to specific phone numbers
$numbers = ['01711111111', '01822222222'];
$message = 'Your message here';
$result = non_musking_send($pdo, $numbers, $message, [
    'message_type' => 'general'
]);

if ($result['success']) {
    echo "Message sent to " . $result['sent_count'] . " recipients";
} else {
    echo "Failed: " . $result['message'];
}
?>
```

## Troubleshooting

### Common Issues

1. **API Credentials Invalid**: Double-check your API key and authentication details
2. **Sender ID Blocked**: Ensure your sender ID is approved by the provider
3. **Rate Limit Exceeded**: Check your provider's rate limits
4. **Invalid Numbers**: Verify phone number format (typically 01XXXXXXXXX)

### Debugging Steps

1. Check the settings in Admin Panel
2. Verify database connectivity
3. Review API response logs
4. Test with a single phone number first
5. Check the messages_log table for delivery status

## Security Considerations

- Store API credentials securely
- Use HTTPS for API calls
- Validate phone numbers before sending
- Implement rate limiting to prevent abuse
- Monitor message logs regularly

## Providers Compatible

This system can work with various SMS providers that offer non-masking services:

- BulkSMSDhaka (non-masking option)
- Green Web
- DLR SMS
- Other local Bangladeshi SMS gateways

## Cost Considerations

Non-masking SMS typically costs less than masking SMS:
- Non-masking: ~0.34 BDT per message
- Masking: ~0.55 BDT per message

Check with your specific provider for current rates.

## Best Practices

1. Keep messages concise and clear
2. Send messages during appropriate hours
3. Maintain updated contact lists
4. Monitor delivery reports
5. Have fallback communication methods
6. Respect privacy and opt-out requests

## Support

For technical support:
- Check the error logs in the messages_log table
- Review API documentation from your SMS provider
- Contact your SMS gateway provider for API-specific issues
- Consult the Bidda project documentation for system-specific questions

---

**Version**: 1.0  
**Last Updated**: January 2026  
**System**: Bidda School Management System