{
  "openapi": "3.0.3",
  "info": {
    "title": "Aria SMS API",
    "version": "1.0.0",
    "description": "Served as /v1/* by sms-service (api.ariaservice.net/sms/v1/*). Authenticate with the session from POST /auth/exchange (the gateway does this for API tokens). The same handlers serve the panel on /api/sms/*. Token scopes: sms:messages:read, sms:messages:write, sms:lines:read, sms:templates:read, sms:templates:write.\n\nWebhooks: configure with PUT /webhook. Each delivery is a POST of {event, occurred_at, data} to your URL with header X-Signature = HMAC-SHA256 of the raw body keyed with your webhook secret; answer 2xx, other answers are retried 5 times with growing delays. Events: message.delivered and message.failed (per message, final delivery state) and inbound.received are sent only when listed in the webhook's events (none by default); batch.completed is always sent. See the WebhookMessageEvent, WebhookInboundEvent and WebhookBatchEvent schemas."
  },
  "servers": [
    {
      "url": "https://api.ariaservice.net/sms/v1"
    }
  ],
  "paths": {
    "/messages": {
      "get": {
        "summary": "List messages",
        "tags": [
          "messages"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of messages",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          },
          {
            "name": "batch_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "queued",
                "sent",
                "delivered",
                "failed",
                "undelivered",
                "rejected",
                "expired"
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "summary": "Send a message to one or more recipients (or schedule it)",
        "tags": [
          "messages"
        ],
        "x-iam-action": "sms:messages:send",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted: {batch_id} or, when scheduled_at is given, {scheduled_id}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendAccepted"
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendRequest"
              }
            }
          }
        }
      }
    },
    "/messages/{message}": {
      "get": {
        "summary": "Show a message",
        "tags": [
          "messages"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Message",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MessageDetail"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "message",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/batches": {
      "get": {
        "summary": "List batches",
        "tags": [
          "batches"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of batches",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Batch"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "processing",
                "partial",
                "completed",
                "failed"
              ]
            }
          }
        ]
      }
    },
    "/batches/{batch}": {
      "get": {
        "summary": "Show a batch",
        "tags": [
          "batches"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Batch",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Batch"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "batch",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/scheduled": {
      "get": {
        "summary": "List scheduled sends",
        "tags": [
          "scheduled"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of scheduled sends",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Scheduled"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          }
        ]
      }
    },
    "/scheduled/{scheduled}": {
      "delete": {
        "summary": "Cancel a pending scheduled send",
        "tags": [
          "scheduled"
        ],
        "x-iam-action": "sms:messages:send",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "204": {
            "description": "Cancelled"
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "scheduled",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/inbound": {
      "get": {
        "summary": "List inbound messages on the account's dedicated lines",
        "tags": [
          "inbound"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of inbound messages",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Inbound"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          }
        ]
      }
    },
    "/lines": {
      "get": {
        "summary": "List the sender lines the account may send from",
        "tags": [
          "lines"
        ],
        "x-iam-action": "sms:lines:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of lines",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Line"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          }
        ]
      },
      "post": {
        "summary": "Request a dedicated line",
        "tags": [
          "lines"
        ],
        "x-iam-action": "sms:lines:request",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "202": {
            "description": "Requested"
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "number": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/templates": {
      "get": {
        "summary": "List templates",
        "tags": [
          "templates"
        ],
        "x-iam-action": "sms:templates:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of templates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          }
        ]
      },
      "post": {
        "summary": "Create a template",
        "tags": [
          "templates"
        ],
        "x-iam-action": "sms:templates:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Template"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TemplateInput"
              }
            }
          }
        }
      }
    },
    "/templates/{template}": {
      "get": {
        "summary": "Show a template",
        "tags": [
          "templates"
        ],
        "x-iam-action": "sms:templates:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Template",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Template"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "template",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "summary": "Update a template",
        "tags": [
          "templates"
        ],
        "x-iam-action": "sms:templates:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Template",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Template"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "template",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TemplateInput"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a template",
        "tags": [
          "templates"
        ],
        "x-iam-action": "sms:templates:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "template",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/blocked-recipients": {
      "get": {
        "summary": "List blocked recipients",
        "tags": [
          "blocked-recipients"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page of blocked recipients",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BlockedRecipient"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          },
          {
            "name": "phone",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "summary": "Block a recipient",
        "tags": [
          "blocked-recipients"
        ],
        "x-iam-action": "sms:blocklist:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/BlockedRecipient"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "phone"
                ],
                "properties": {
                  "phone": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/blocked-recipients/{blockedRecipient}": {
      "delete": {
        "summary": "Unblock a recipient",
        "tags": [
          "blocked-recipients"
        ],
        "x-iam-action": "sms:blocklist:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "blockedRecipient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/webhook": {
      "get": {
        "summary": "Show the webhook settings",
        "tags": [
          "webhook"
        ],
        "x-iam-action": "sms:webhooks:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Set the webhook URL, enabled flag and subscribed events",
        "tags": [
          "webhook"
        ],
        "x-iam-action": "sms:webhooks:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookUpdate"
              }
            }
          }
        }
      }
    },
    "/webhook/secret": {
      "post": {
        "summary": "Rotate the webhook signing secret",
        "tags": [
          "webhook"
        ],
        "x-iam-action": "sms:webhooks:write",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "New secret",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/reports/summary": {
      "get": {
        "summary": "Delivery and spend summary",
        "tags": [
          "reports"
        ],
        "x-iam-action": "sms:reports:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Summary",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Summary"
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ]
      }
    },
    "/prices": {
      "get": {
        "summary": "Per-message price of the caller's pricing profile",
        "tags": [
          "prices"
        ],
        "x-iam-action": "sms:messages:read",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Prices",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Prices"
                }
              }
            }
          },
          "default": {
            "description": "Error {code, message}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "session": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "insufficient_balance (402), identity_needed (403), forbidden (403), account_suspended (403), validation_failed (422), not_found (404), rate_limited (429)"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "PageMeta": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer"
          },
          "current_page": {
            "type": "integer"
          },
          "per_page": {
            "type": "integer"
          }
        }
      },
      "SendRequest": {
        "type": "object",
        "required": [
          "recipients",
          "from"
        ],
        "properties": {
          "recipients": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          },
          "body": {
            "type": "string",
            "maxLength": 2000
          },
          "template_id": {
            "type": "integer"
          },
          "from": {
            "type": "integer",
            "description": "sender line id"
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time"
          },
          "client_reference": {
            "type": "string",
            "description": "idempotency reference; the Idempotency-Key header is used when absent"
          }
        }
      },
      "SendAccepted": {
        "type": "object",
        "properties": {
          "batch_id": {
            "type": "string"
          },
          "scheduled_id": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "total_recipients": {
            "type": "integer"
          },
          "total_cost_rial": {
            "type": "integer"
          },
          "filtered_blocked_count": {
            "type": "integer"
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "batch_id": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "from": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "parts": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sent",
              "delivered",
              "failed",
              "undelivered",
              "rejected",
              "expired"
            ],
            "description": "queued: waiting to be sent; sent: accepted by the operator; delivered: reached the handset; failed: the provider refused it (not charged); undelivered: the operator accepted it but it did not reach the handset; rejected; expired"
          },
          "cost_rial": {
            "type": "integer",
            "description": "0 for a message the provider refused"
          },
          "error": {
            "type": "string",
            "nullable": true
          },
          "queued_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "when the message was created and queued"
          },
          "encoding": {
            "type": "string",
            "nullable": true,
            "description": "text encoding, lowercased (unicode, gsm7, ...)"
          },
          "operator": {
            "type": "string",
            "enum": [
              "mci",
              "mtn",
              "rightel",
              "other"
            ],
            "description": "recipient's operator by number prefix (best effort: ported numbers keep their original prefix)"
          },
          "provider": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "nullable": true,
                "description": "provider slug, e.g. magfa"
              },
              "message_id": {
                "type": "string",
                "nullable": true,
                "description": "the provider's message id (operator tracking number)"
              },
              "status_code": {
                "type": "integer",
                "nullable": true,
                "description": "last raw delivery status code (Magfa: -1, 0, 1, 2, 8, 16)"
              },
              "error_code": {
                "type": "string",
                "nullable": true,
                "description": "raw submit error code when the provider refused the message"
              }
            }
          },
          "delivery_checks": {
            "type": "integer",
            "description": "how many delivery-status checks ran"
          },
          "last_checked_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "last delivery-status check"
          },
          "sent_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "delivered_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          }
        }
      },
      "Batch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string",
            "nullable": true,
            "description": "client_reference"
          },
          "from": {
            "type": "string",
            "nullable": true
          },
          "body": {
            "type": "string",
            "description": "text of the first message"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "processing",
              "partial",
              "completed",
              "failed"
            ]
          },
          "recipients": {
            "type": "integer"
          },
          "parts": {
            "type": "integer"
          },
          "sent": {
            "type": "integer"
          },
          "delivered": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "cost_rial": {
            "type": "integer",
            "description": "charged amount, refunds for refused messages deducted"
          },
          "scheduled_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "channel": {
            "type": "string",
            "enum": [
              "panel",
              "api",
              "system"
            ],
            "description": "how the batch was submitted"
          },
          "sender_ip": {
            "type": "string",
            "nullable": true,
            "description": "masked sender address: 85.133.133.x, or the first three IPv6 groups followed by :x"
          },
          "completed_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "when the batch reached its final status"
          },
          "created_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          }
        }
      },
      "Scheduled": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "from": {
            "type": "string",
            "nullable": true
          },
          "body": {
            "type": "string"
          },
          "recipients": {
            "type": "integer",
            "description": "recipient count"
          },
          "scheduled_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "processing",
              "sent",
              "failed",
              "cancelled"
            ]
          }
        }
      },
      "Inbound": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "received_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          }
        }
      },
      "Line": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "number": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "dedicated",
              "shared"
            ]
          },
          "can_receive_inbound": {
            "type": "boolean"
          },
          "is_default": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "note": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          }
        }
      },
      "TemplateInput": {
        "type": "object",
        "required": [
          "name",
          "body"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "body": {
            "type": "string"
          }
        }
      },
      "BlockedRecipient": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "mobile": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "empty when unset"
          },
          "enabled": {
            "type": "boolean"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventName"
            },
            "description": "Subscribed per-message events; empty until the customer chooses some (batch.completed is always sent)"
          },
          "secret_hint": {
            "type": "string",
            "nullable": true,
            "description": "masked tail of the signing secret; the full secret is only returned by POST /webhook/secret"
          }
        }
      },
      "Summary": {
        "type": "object",
        "properties": {
          "sent": {
            "type": "integer"
          },
          "delivered": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "spend_rial": {
            "type": "integer"
          },
          "daily": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string"
                },
                "sent": {
                  "type": "integer"
                },
                "delivered": {
                  "type": "integer"
                },
                "failed": {
                  "type": "integer"
                },
                "spend_rial": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "Prices": {
        "type": "object",
        "properties": {
          "billing_unit": {
            "type": "string",
            "enum": [
              "message",
              "part"
            ],
            "description": "What unit_rial is charged per: one message (default, SMS_BILLING_QUANTITY=messages) or one SMS part"
          },
          "unit_rial": {
            "type": "integer"
          },
          "tiers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "min": {
                  "type": "integer"
                },
                "unit_rial": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "WebhookEventName": {
        "type": "string",
        "enum": [
          "message.delivered",
          "message.failed",
          "inbound.received"
        ],
        "description": "Subscribable webhook events. batch.completed is always sent and cannot be unsubscribed."
      },
      "WebhookUpdate": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "nullable": true,
            "format": "uri"
          },
          "enabled": {
            "type": "boolean"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventName"
            }
          }
        }
      },
      "WebhookMessageEvent": {
        "type": "object",
        "required": [
          "event",
          "occurred_at",
          "data"
        ],
        "description": "Event message.delivered or message.failed (event is the one that happened). data is the Message as GET /messages/{message} returns it, in its final state (status delivered for message.delivered; failed, undelivered, rejected or expired for message.failed).",
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "message.delivered",
              "message.failed"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "$ref": "#/components/schemas/Message"
          }
        }
      },
      "WebhookInboundEvent": {
        "type": "object",
        "required": [
          "event",
          "occurred_at",
          "data"
        ],
        "description": "An SMS received on one of the customer's dedicated lines; data is the Inbound object.",
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "inbound.received"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "$ref": "#/components/schemas/Inbound"
          }
        }
      },
      "WebhookBatchEvent": {
        "type": "object",
        "required": [
          "event",
          "occurred_at",
          "data"
        ],
        "description": "Sent once when a batch reaches a final status. data is the Batch object. For existing receivers the original flat fields are kept at the top level as well: batch_id, client_reference, status (stored value: sent, partially_sent or failed), total_recipients, delivered_count, failed_count, completed_at.",
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "batch.completed"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "$ref": "#/components/schemas/Batch"
          }
        }
      },
      "MessageTimelineEvent": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "queued",
              "sent_to_provider",
              "provider_refused",
              "status_checked",
              "delivered_to_operator",
              "delivered",
              "not_delivered",
              "not_sent_to_operator",
              "expired",
              "rejected"
            ],
            "description": "queued: created; sent_to_provider: accepted by the provider; provider_refused: refused at submit (refunded); status_checked: a delivery check returned a non-final code (0 = no status yet); delivered_to_operator: code 8, reached the telecom; delivered: code 1; not_delivered: code 2; not_sent_to_operator: code 16; expired: code -1 or the 24h window ended; rejected: blocked locally"
          },
          "at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "event time, microsecond precision"
          },
          "status_code": {
            "type": "integer",
            "nullable": true
          },
          "error_code": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "MessageDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Message"
          },
          {
            "type": "object",
            "properties": {
              "timeline": {
                "type": "array",
                "description": "ordered by at ascending; synthesized from the message's timestamps for messages created before the event log existed",
                "items": {
                  "$ref": "#/components/schemas/MessageTimelineEvent"
                }
              }
            }
          }
        ]
      }
    }
  },
  "x-webhooks": {
    "message.delivered": {
      "post": {
        "summary": "Event message.delivered",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookMessageEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Any 2xx acknowledges the event"
          }
        }
      }
    },
    "message.failed": {
      "post": {
        "summary": "Event message.failed",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookMessageEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Any 2xx acknowledges the event"
          }
        }
      }
    },
    "inbound.received": {
      "post": {
        "summary": "Event inbound.received",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInboundEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Any 2xx acknowledges the event"
          }
        }
      }
    },
    "batch.completed": {
      "post": {
        "summary": "Event batch.completed",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookBatchEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Any 2xx acknowledges the event"
          }
        }
      }
    }
  }
}
