Get message status

Once you've sent your Message and retrieved the Message Id (see Send Text Message for details on how to do this), you may want to know what state your Message is currently in. To find this out we again use the Send Service object. The following script sends a Message and then checks the status of it, the example page is included in the SDK called GetMessageStatus.asp.


function processForm()
'Turn off error handling and implement it manually
on error resume next

'Create the service object
dim sendService
set sendService = Server.CreateObject("Esendex.SendService.2")

'Error Handling
if err.number <> 0 then
processForm = "Unable to create Esendex.SendService.2 object. Ensure COM object is registered. Error description: " + err.Description
exit function
end if

'Setup the send service object
sendService.Initialise Request.Form("Username"), Request.Form("Password"), Request.Form("Account")

'Send a message and retrieve the message ID
dim messageID
dim messageStatus
dim errorCode

'messageID = sendService.SendMessage(Request.Form("recipient"), Request.Form("body"), 1)
messageID = "86892ba2-66ef-4909-a3be-935b4982e09e"
if err.number <> 0 then
'Get the error code!!
errorCode = err.number And &HFFFF&

'Create the message to display
processForm = "Unable to send message: " + err.Description + ". Error Code: " + CStr(errorCode)
exit function
else
'Check the status of the message
messageStatus = sendService.GetMessageStatus(messageID)

if err.number <> 0 then
'Get the error code!!
errorCode = err.number And &HFFFF&

'Create the message to display
processForm = "Unable to get the message status: " + err.Description + ". Error Code: " + CStr(errorCode)
exit function
else
processForm = "Message Status: " + CStr(messageStatus)
end if
end if
end function

As in the Send Message example we have to create and initialise a Send Service object; if you're unsure how to do this then read through Send Text Message. Next a Message is sent to the recipient mobile and the Message Id that was returned is stored. This is what will be used to find out the current status of the Message.

The code to check the Message Status is.


messageStatus = sendService.GetMessageStatus(messageID)

A status code is returned from this method call which relates to the status of the Message with the Id that was passed in. When a Message is received by us the status will be 1, queued. Then we will process the Message and send it to the relevant network provider, this will have a status of 2, sent.

Once we have received a delivery receipt from the network we set the status to 3, delivered. If there are problems delivering the Message then the status is set to 4, failed. So the different return values and what they mean are...
1 = Queued
2 = Sent
3 = Delivered
4 = Failed