# How to Configure Sending SMS via Alpha SMS

Alpha SMS allows sending SMS messages, including OTP (one-time-password) for client verification. This is useful for providing access to a wide range of services (discounts, personal account, online payment capability, and more).

> 📖 **Documentation:** For more details about Alpha SMS API, read on the [official website](https://alphasms.ua/api/).

---

## Prerequisites

- Active Alpha SMS account
- API key from Alpha SMS
- Registered alpha name for mailings

---

## Obtaining API Key

1. Sign in to [Alpha SMS management panel](https://alphasms.ua/)
2. Go to the API section
3. Create or copy the API key

---

## Obtaining Alpha Name

1. In the Alpha SMS panel, go to the settings section
2. Register an alpha name for mailings
3. Wait for approval

---

## Configuring action sms_alphasms_send

For sending SMS, the **sms_alphasms_send** action is used.

### Configuration

Fill in the JSON config:

```json
{
  "auth": "635f14be894033beded246d3adf9b199fdd51e06",
  "url": "https://alphasms.ua/api/http.php",
  "sms_signature": "Alpha"
}
```

**Parameters:**
- `auth` — your API key to the Alphasms service
- `url` — API URL for requests to the Alphasms service
- `sms_signature` — alpha name for mailings (obtained through the Alphasms service)

---

## Required Variables

For correct action operation, you need to have 3 variables in state:

- `otp` — OTP generated on the ConnectiveOne side
- `phone` — user phone number to which the SMS message will be sent
- `id` — sequential message number (must be unique)

> ⚠️ **Important:** Variables must be set in state before calling the action.

---

## Example Scenario Configuration for Sending OTP

### Step 1: Generating OTP and ID

Use action for generation:

```json
{
  "id": "roundTo(random(1)*1000000,0)",
  "otp": "roundTo(random(1)*10000,0)"
}
```

**Explanation:**
- `id` — 6-digit message number (random number from 0 to 1 is generated, multiplied by 1000000, rounded)
- `otp` — 4-digit OTP for sending to user (random number from 0 to 1 is generated, multiplied by 10000, rounded)

### Step 2: Getting Phone Number

Get the user's phone number through the "Wait for user response" block with phone number validation setting.

### Step 3: Using sms_alphasms_send

After generating OTP and getting the phone number, use the **sms_alphasms_send** action.

**Result:** In case of success, the previously generated OTP code will arrive at the specified user number.

### Step 4: Verifying Entered Code

After successful sending, add a block to verify the code entered by the user.

**JSON config setting for if_else action:**

```json
{
  "if": {
    "{{sended_otp}}=={{otp}}": "ok",
    "event": "ok"
  }
}
```

**Logic:**
- If `sended_otp` equals `otp` — transition by `ok` event
- On success, the user gets access to information
- If verification is not passed — they will be offered to retry or contact the operator

---

## Error Handling

If SMS sending ended with an error, the action returns `"error"`. In the scenario, you can handle this event for:

- Retry
- Sending message to user
- Transfer to operator

---

## Limitations

- Action configuration requires access to a third-party SMS sending service API and basic JSON knowledge
- Phone number must be in the correct format (depends on Alphasms requirements)
- OTP code must be numeric
- Message ID must be unique

---

## Related Articles

- [AlphaSMS API Documentation](https://alphasms.ua/api/) — official AlphaSMS documentation
- [Create custom action](/en/actionjail/how-to/admin-manage-actions.md) — creating custom actions through ActionJail

