Normal Topic Creating an SMS/Text Function (Read 6883 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Creating an SMS/Text Function
May 13th, 2013 at 11:14pm
Print Post Print Post  
Hi all,

I just managed to integrate SMS functionality into my system in conjunction with a texting service called SMSgateway.ca ... I thought you might find some of this code interesting.

This hard codes our user key, so it's been replaced with 123456789.

Code
Select All
var vCell as string
var vStaff as string = DBColl#
var vStaffName as string
var vStaffExt as string
var vSubject as string
var vSMSRun as string
var vStaffEmail as string

vStaffName = @xlookup(@FN,vStaff,"Staff Screen!StaffRef", "StaffName")
vStaffExt = @xlookup(@FN,vStaff,"Staff Screen!StaffRef", "StaffExt")
vStaffEmail = @xlookup(@FN, vStaff, "Staff Screen!StaffRef", "StaffEmail")
vSubject = "This is a message for " + DBName + " to call the office of " + vStaffName + " at " + vStaffExt + " or by email at " + vStaffEmail

PopUpSelectPosition(1, @Xpos(DBPd), @Ypos(DBPd))
vCell = @PromptForUserInput("Text To Cell Number:",DBTel1)
vSubject = @PromptForUserInput("Message?",vSubject)

vSubject = @replace(vSubject, " ", "%20")

IF vCell <> "" THEN
{
	ThrowFocus(DBNote0)
	vSMSRun = @ASynchShell("http://smsgateway.ca/sendsms.aspx?CellNumber=" + vCell + "&MessageBody=" + vSubject + "&AccountKey=123456789")
	DBNote0 = "SMS [" + vCell + "]: " + @replace(vSubject,"%20", " ")

}
 

  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating an SMS/Text Function
Reply #1 - May 15th, 2013 at 8:40pm
Print Post Print Post  
Does that make your browser come up?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Creating an SMS/Text Function
Reply #2 - May 16th, 2013 at 1:42pm
Print Post Print Post  
It does ... I want to build a batch function that closes the browser tab, so if I run 1000 texts in a batch, I don't melt down IE or Firefox ...
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Creating an SMS/Text Function
Reply #3 - May 16th, 2013 at 3:16pm
Print Post Print Post  
You should consider replacing the ASynchShell call with @HTTPGetHTML or @HTTPPostHTML. These commands will send a GET or POST request to a web server just like a browser would, but without the need for a browser or any further automation.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating an SMS/Text Function
Reply #4 - May 21st, 2013 at 10:27pm
Print Post Print Post  
The Cow wrote on May 16th, 2013 at 3:16pm:
You should consider replacing the ASynchShell call with @HTTPGetHTML or @HTTPPostHTML. These commands will send a GET or POST request to a web server just like a browser would, but without the need for a browser or any further automation.

Yes. This.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Creating an SMS/Text Function
Reply #5 - May 27th, 2013 at 2:39pm
Print Post Print Post  
Hi all,

So I tried a simple @HTTPPostHTML and it worked, but now that I'm trying to program a Mass Update, I'm getting an <h1>invalid URL</h1> error

Here's what the html output should look like:

Code
Select All
http://smsgateway.ca/sendsms.aspx?CellNumber=226-946-1730&MessageBody=This%20is%20a%20message%20for%20Adekunie%20Olumide%20to%20call%20the%20office%20of%20%Blair20at%20226-555-1212%20or%20by%20email%20at%20test@test.com&AccountKey=123456789ABCD
 



Here's what I'm trying ...

Code
Select All
var vhtml as string
var aa as string

vhtml = @chr(34)+"/sendsms.aspx?CellNumber="&DBTel1&"&MessageBody=This%20is%20a%20message%20for%20"&DBName&"%20to%20contact%20the%20office%20of%20"&DBStaff&"%20at%20"&DBStaffNumber&"%20or%20by%20email%20at%20"&DBStaffEmail&"&AccountKey=123456789ABCD"+@chr(34)
vhtml = @replace(vhtml," ","%20")

aa = @HTTPPostHTML("www.smsgateway.ca", vhtml,"",80,"")
 



Is the problem the @chr quotation marks I'm adding?  I've tried with and without ...

Thanks!
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Creating an SMS/Text Function
Reply #6 - May 27th, 2013 at 3:03pm
Print Post Print Post  
It may be that using "&" for string concatenation is a problem. Try using "+" instead.

Look for errors in the formatting by splitting the long string onto several lines, using "+" at the end of each line to join the string - making it a lot easier to see any errors.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Creating an SMS/Text Function
Reply #7 - May 27th, 2013 at 5:01pm
Print Post Print Post  
Well, I seem to have things working ... once I took out the @chr(34) out of the string and replaced the '&' with '+', everything flowed smoothly.
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Creating an SMS/Text Function
Reply #8 - May 27th, 2013 at 6:05pm
Print Post Print Post  
Please post the final working code (sans private info) so others can use it as an example.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Creating an SMS/Text Function
Reply #9 - Jun 16th, 2013 at 3:01am
Print Post Print Post  
Sure thing!

Code
Select All
var vCell as string
var vStaff as string = DBColl#
var vStaffName as string
var vStaffExt as string
var vSubject as string
var vSMSRun as string
var vStaffEmail as string
var vHTML as string

vStaffName = @xlookup(@FN,vStaff,"Staff Screen!StaffRef", "StaffName")
vStaffExt = @xlookup(@FN,vStaff,"Staff Screen!StaffRef", "StaffExt")
vStaffEmail = @xlookup(@FN, vStaff, "Staff Screen!StaffRef", "StaffEmail")
vSubject = "This is a message for " + DBName + " to call the office of " + vStaffName + " at " + vStaffExt + " or by email at " + vStaffEmail

PopUpSelectPosition(1, @Xpos(DBPd), @Ypos(DBPd))
vCell = @PromptForUserInput("Text To Cell Number:",DBTel1)
vSubject = @PromptForUserInput("Message?",vSubject)

vSubject = @replace(vSubject, " ", "%20")

IF vCell <> "" THEN
{
	ThrowFocus(DBNote0)
	vHTML = "http://smsgateway.ca/sendsms.aspx?CellNumber=" + vCell + "&MessageBody=" + vSubject + "&AccountKey=123456789ABC"
	vSMSRun = @HTTPPostHTML("www.smsgateway.ca", vhtml,"",80,"")

	DBNote0 = "SMS [" + vCell + "]: " + @replace(vSubject,"%20", " ")

}
 

  
Back to top
IP Logged