Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.0.0+

Clickatell One API: Schedule a time-limited SMS reminder

See more Clickatell Examples

Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.

Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.

Clickatell API reference

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
set http [new_CkHttp]

CkHttp_put_RequireSslCertVerify $http 1
#  Load the key for this One API integration from your application configuration.
CkHttp_SetRequestHeader $http "Authorization" "ONE_API_KEY"
CkHttp_SetRequestHeader $http "Accept" "application/json"

set schedule [new_CkDateTime]

CkDateTime_SetFromCurrentSystemTime $schedule
CkDateTime_AddSeconds $schedule 900
set sendAt [CkDateTime_getAsTimestamp $schedule 0]
set body [new_CkJsonObject]

CkJsonObject_UpdateString $body "messages[0].channel" "sms"
CkJsonObject_UpdateString $body "messages[0].to" "PHONE_NUMBER"
CkJsonObject_UpdateString $body "messages[0].content" "Appointment reminder: please check in at reception."
CkJsonObject_UpdateString $body "messages[0].scheduledDeliveryTime" $sendAt
CkJsonObject_UpdateInt $body "messages[0].validityPeriod" 60
set sender ""
if {$sender != ""} then {
    CkJsonObject_UpdateString $body "messages[0].from" $sender
}

puts "Requested send time (UTC): $sendAt"

set resp [new_CkHttpResponse]

set sent [CkHttp_HttpJson $http "POST" "https://platform.clickatell.com/v1/message" $body "application/json" $resp]
if {[CkHttpResponse_get_StatusCode $resp] == 0} then {
    puts "No HTTP response. Check the message report before resending."
    delete_CkHttp $http
    delete_CkDateTime $schedule
    delete_CkJsonObject $body
    delete_CkHttpResponse $resp
    exit
}

set reply [new_CkJsonObject]

set parsed [CkJsonObject_Load $reply [CkHttpResponse_bodyStr $resp]]
if {expr [$sent != 1]  ||  [[CkHttpResponse_get_StatusCode $resp] != 202]} then {
    puts "Send returned HTTP [CkHttpResponse_get_StatusCode $resp]"
    if {[CkJsonObject_HasMember $reply "error.description"] == 1} then {
        puts [CkJsonObject_stringOf $reply error.description]
    }

    delete_CkHttp $http
    delete_CkDateTime $schedule
    delete_CkJsonObject $body
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

if {[CkJsonObject_HasMember $reply "error.code"] == 1} then {
    if {[CkJsonObject_IsNullOf $reply "error.code"] != 1} then {
        puts "Submission error [CkJsonObject_stringOf $reply error.code]  [CkJsonObject_stringOf $reply error.description]"
        delete_CkHttp $http
        delete_CkDateTime $schedule
        delete_CkJsonObject $body
        delete_CkHttpResponse $resp
        delete_CkJsonObject $reply
        exit
    }

}

#  HTTP acceptance and the recipient result are separate checks.
if {expr [$parsed != 1]  ||  [[CkJsonObject_JsonTypeOf $reply "messages[0].accepted"] != 5]} then {
    puts "Missing recipient result. Check the message report."
    delete_CkHttp $http
    delete_CkDateTime $schedule
    delete_CkJsonObject $body
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

if {[CkJsonObject_BoolOf $reply "messages[0].accepted"] != 1} then {
    puts "Message rejected: [CkJsonObject_stringOf $reply {messages[0].error.code}]  [CkJsonObject_stringOf $reply {messages[0].error.description}]"
    delete_CkHttp $http
    delete_CkDateTime $schedule
    delete_CkJsonObject $body
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

if {[CkJsonObject_JsonTypeOf $reply "messages[0].apiMessageId"] != 1} then {
    puts "Accepted without a message ID. Check the message report."
    delete_CkHttp $http
    delete_CkDateTime $schedule
    delete_CkJsonObject $body
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

puts "Accepted. Message ID: [CkJsonObject_stringOf $reply {messages[0].apiMessageId}]"

delete_CkHttp $http
delete_CkDateTime $schedule
delete_CkJsonObject $body
delete_CkHttpResponse $resp
delete_CkJsonObject $reply