# Text.lk API Configuration

## Your API Credentials

Based on the credentials you provided, add these to your `.env` file:

```env
# Text.lk SMS Configuration
TEXT_LK_API_TOKEN=2396|Cabsm0McwWihFpWK6MXIcdDvnmvCXwTvu6aAMcIQ640a6ebd
TEXT_LK_API_URL=https://app.text.lk/api/http
TEXT_LK_SENDER_ID=YOUR_SENDER_ID
```

**Note:** The system will automatically append `/sms/send` to the base URL. You can set `TEXT_LK_API_URL` to just the base URL (`https://app.text.lk/api/http`) or the full endpoint (`https://app.text.lk/api/http/sms/send`).

## Quick Setup Steps

1. **Open** `backend/.env` file

2. **Add** the configuration above (replace `YOUR_SENDER_ID` with your actual sender ID if you have one, or leave it as is if you don't have one)

3. **Restart** your backend server:
   ```bash
   npm run dev
   ```

4. **Test** using the Admin Test SMS page or by submitting an inquiry

## API Endpoints Available

- **HTTP API Base**: `https://app.text.lk/api/http/`
- **HTTP API SMS Endpoint**: `https://app.text.lk/api/http/sms/send` ✅ (Currently configured)
- **OAuth 2.0 API**: `https://app.text.lk/api/v3/` (Available for future use if needed)

## API Request Format

The Text.lk HTTP API expects:
- **Endpoint**: `POST https://app.text.lk/api/http/sms/send`
- **Field name**: `recipient` (not `to`) - **Required**
- **Field name**: `message` - **Required**
- **Field name**: `api_token` - **Required** (in request body)
- **Optional**: `sender_id` - Can be:
  - A telephone number (including country code)
  - An alphanumeric string (maximum 11 characters)
  - Must be authorized in your Text.lk account

## Important Notes

⚠️ **Sender ID Authorization**: Text.lk requires an authorized sender ID. If you don't have one:
1. Log in to your Text.lk dashboard
2. Check your authorized sender IDs in Settings
3. Set `TEXT_LK_SENDER_ID` in `.env` to one of your authorized sender IDs
4. Or contact Text.lk support to authorize a sender ID

If you don't set a sender ID, Text.lk will use your account's default sender ID (if available).

## Notes

- The API token format includes a user ID and token separated by `|`
- The token is used for Bearer authentication
- Phone numbers are automatically formatted to Sri Lankan format (94XXXXXXXXX)
- Sender ID is optional but recommended for better message delivery

## Testing

After configuration, test by:
1. Creating a test order
2. Checking backend console for SMS logs
3. Verifying the recipient receives the SMS

If you see errors, check:
- Token is correct and not expired
- Account has sufficient balance
- Phone number format is correct

