NetTalk Central

The Rest Of NetTalk => The Rest - Ask For Help => Topic started by: Johan van Zyl on May 17, 2013, 11:21:24 PM

Title: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 17, 2013, 11:21:24 PM
This works:
set(locums)
loop until Access:Locums.Next()
    loc:MobileNo = '27'& sub(clip(LCM:Cell),2 , len(clip(LCM:Cell)))
    IF LEN(clip(loc:MobileNo)) = 11
       loc:SendToBatch = clip(loc:SendToBatch)&','& clip(loc:MobileNo   
END
loc:SendToBatch = sub(loc:SendToBatch,1,len(clip(loc:SendToBatch))-1)



This does not:
set(Locums)
!I# = 0
!!loop through file and concatenate numbers!
!loop until Access:Locums.Next()
!    I#+=1
!    !debuginfo('in the loop '&I# )
!    loc:MobileNo = '27'& sub(clip(LCM:Cell),2 , len(clip(LCM:Cell)))
!    debuginfo(loc:MobileNo)
!    ds_Sleep(100) ! even this did not help
!    IF LEN(clip(loc:MobileNo)) = 11 !and LOC:MobileNo  = '27720541936'!this line does not work
!IF LEN(clip(loc:MobileNo)) = 11 and LOC:MobileNo  = '27720541936' !this works - if I only send one number at a time
!        do sendmessage
!    end   
!end   

SendMessage ROUTINE

    !LOC:PostURL   = 'http://api.clickatell.com/http/sendmsg?user='&clip(loc:ClickatellUserName)&'&password='& clip(loc:ClickatellPassword)&'&api_id='&clip(loc:ClickatellAPIID) &'&to='&clip(loc:MobileNo) &'&text='&clip(loc:Message) !this does not work
   
    LOC:PostURL   = 'http://api.clickatell.com/http/sendmsg?user='&clip(loc:ClickatellUserName)&'&password='& clip(loc:ClickatellPassword)&'&api_id='&clip(loc:ClickatellAPIID) &'&to='&clip(loc:SendToBatch) &'&text='&clip(loc:Message) ! this works - concatenated all the numbers - but there is a limit to thi
    ThisClient.Post(clip(LOC:PostURL),'')  ! cookies, and fields automatically used.
    DEBUGINFO(loc:MobileNo &' WAS SENT')
      !do logSMSMessage
      display()
   ! END
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 20, 2013, 03:44:52 PM
This issue is still unresolved.
I need loop through a table and send SMS's to all or some of the persons in that table.
In its simplest form:
set(locums)
loop until Access:locums.Next()
 LOC:PostURL   = 'http://api.clickatell.com/http/sendmsg?user='&clip(loc:ClickatellUserName)&'&password='& clip(loc:ClickatellPassword)&'&api_id='&clip(loc:ClickatellAPIID) &'&to='&clip(LCM:CellNo) &'&text='&clip(loc:Message)
    ThisClient.Post(clip(LOC:PostURL),'')

Apparently there must be some kind of "pause" or ErrorTrapping here.
Are there any sample apps or code to help me here?

end
Title: Re: WebClient Clicatell and many SMS's
Post by: Bruce on May 20, 2013, 07:26:54 PM
TCP/IP comms is asyncronous.
Meaning that you can't do a Post inside a loop likw that. You must do one Post, then wait for it to complete (in .PageReceived) before doing the next.

So you have two approaches;
a) build a queue of all the sms's
b) Post one, wait for it to complete (.PageReceived) or fail (.ErrorTrap) and at that point do the next one.

or

a) make a procedure to send one sms - which closes automaticallly in .PageReceived  and .ErrorTrap and
b) call this procedure from inside your loop.

If you look at the "Sending Email from a process" example you'll see the same approach.

cheers
Bruce
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 20, 2013, 11:04:35 PM
Would
loc:Response = self.Page
in PageReceived be sufficient?
Title: Re: WebClient Clicatell and many SMS's
Post by: Bruce on May 20, 2013, 11:08:15 PM
what you really want to do in .PageReceived is
a) handle the response in any way you like and
b) Post the next request.

you can ignore the response completely if you like, but it's going to need you to do a POST there if you want it to send another sms at that point.

cheers
Bruce
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 21, 2013, 12:00:49 PM
Decided to use a process but I cannot get it to send SMS's.

TakeRecord code:
loc:message = clip(LOC:Message)
loc:Cell = clip(SSM:Cell)           
LOC:PostURL   = 'http://api.clickatell.com/http/sendmsg?user='&clip(loc:ClickatellUserName)&'&password='& clip(loc:ClickatellPassword)&'&api_id='&clip(loc:ClickatellAPIID) &'&to='&clip(loc:Cell) &'&text='&clip(loc:Message)
stop(clip(LOC:PostURL)) ! this seems to be correct.
ThisClient.Post(clip(LOC:PostURL),'')  !Just nothing happens



[attachment deleted by admin]
Title: Re: WebClient Clicatell and many SMS's
Post by: Bruce on May 21, 2013, 10:01:06 PM
Putting a STOP or MESSAGE in the procedure will break the Events, and hence break the procedure itself.
Use Debugview.Exe, and thisClient._trace('whatever') lines in the code if you want to see what is happening.

cheers
Bruce
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 21, 2013, 10:19:05 PM
Did that but it seems that the code in .PageReceived is never executed.
Title: Re: WebClient Clicatell and many SMS's
Post by: Bruce on May 21, 2013, 10:26:30 PM
have you added code to .ErrorTrap?
does it go into there instead?

cheers
Bruce
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 21, 2013, 10:28:30 PM
OK was calling the post in a routine and not in a procedure.
Now I get attached error

[attachment deleted by admin]
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 21, 2013, 10:46:58 PM
OK not passing parameters to the procedure!!!
Will get back to you.
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 22, 2013, 11:03:53 AM
OK - I have a process that calls a procedure as it goes through the loop.
But it still does not work. Just nothing happens - not even error messages!
Where exactly must I put this code?
ThisClient.Post(clip(loc:PostURL),'')

[attachment deleted by admin]
Title: Re: WebClient Clicatell and many SMS's
Post by: Johan van Zyl on May 22, 2013, 11:29:20 AM
Resolved!
Right! - the window called by the Process had to be NON MDI and must be Immediate.
Not sure if I have the
ThisClient.Post(clip(loc:PostURL),'')
in quite the correct place - I have placed it on the Button?