Skip to content

Delivery status

After a message is sent you can ask the API where it stands. A single message is looked up by its id, and a bulk task is looked up by its task id.

One message

status = client.message_status("message-id")
print(status.status_code, status.status_text)

message_status returns a MessageStatus. The raw status_code and human status_text come straight from the API. The client also gives you a typed status and an is_final flag, so you do not have to remember the numbers.

from onesms import DeliveryStatus

status = client.message_status("message-id")

if status.is_final:
    if status.status is DeliveryStatus.DELIVERED:
        print("Delivered")
    else:
        print("Not delivered:", status.status_text)
else:
    print("Still in progress")

Status codes

DeliveryStatus maps every code the API can return.

Code Name Final
0 PENDING No
1 SENT_TO_OPERATOR No
2 DELIVERED Yes
3 EXPIRED Yes
5 UNDELIVERED Yes
8 REJECTED Yes
9 OPERATOR_UNREACHABLE Yes

A final status will not change again, so it is safe to stop polling once is_final is true. If you are working with plain integers, delivery_status(code) and is_final_status(code) do the same job without an object:

from onesms import delivery_status, is_final_status

print(delivery_status(2))       # DeliveryStatus.DELIVERED
print(is_final_status(0))       # False

A bulk task

from onesms import Channel

task = client.task_status("task-id", channel=Channel.NOTIFICATION)
print(task.sent_count, task.failed_count)

for message in task.messages:
    print(message.phone, message.status_text, message.is_final)

Pass the channel that matches the send: Channel.NOTIFICATION for notification tasks and Channel.ADVERTISING for advertising tasks. Each entry in task.messages carries the same status and is_final helpers as a single lookup.