Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

SMS Messaging

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Working Code - SMS Twilio

    Ok, after a while I started to figure out what I needed to do. Here is the working xbasic code for me.

    Code:
    FUNCTION SendTw AS C (e as p)
    
    debug(1)
    '==CONNECTION AND VARS
    dim cn as SQL::Connection
    dim vHasError as c
    dim cf_1 as extension::CurlFile
    dim flag_1 as l
    dim ce as extension::Curl	
    dim vSendNumber as c
    
    
    vHasError = "N"
    
    cn.open("::Name::DropsConn")
    
    vTwilioURLPre= "https://api.twilio.com/2010-04-01/Accounts/"
    vSID = "my-SID-here"
    vTwilioURL=vTwilioURLPre+vSID+"/Messages.json"
    vToken = "my-TOKEN-here"
    vPassword=vSID+":"+vToken
    vFromNumber="my-TwilioNUMBER-here"
    vFrom="&From="+vFromNumber
    
    
    vSubject = "New post"
    vMessage = "There is a post"
    
    ' trying to grab all of the recipients phone numbers from the sharedto table - so this will send to multiple people.
    'this assumes you have a table called sharedto with columns named phone,notify and userid.
    vSelect = "SELECT phone FROM sharedto WHERE notify = 'Yes' and userid = 'my-Email-here' "
    cn.execute(vSelect)
    
    ce = extension::Curl.Init()
    ce.setOpt("URL",vTwilioURL)
    ce.setOpt("NOPROGRESS",1)
    ce.setOpt("USERPWD",vPassword)
    ce.setOpt("USERAGENT","curl/7.34.0")
    ce.setOpt("MAXREDIRS",50)
    ce.setOpt("CAINFO","C:\\Program Files (x86)\\a5V12\\CARoot\\ca-cert.pem")
    ce.setOpt("CAPATH","C:\\Program Files (x86)\\a5V12\\CARoot")
    ce.setOpt("CUSTOMREQUEST","POST")
    ce.setOpt("TCP_KEEPALIVE",1)
    
    vBody = "Body="+urlencode(vMessage)
    
    while eval_valid(cn.ResultSet.data("phone"))
    	
    vSendNumber= cn.ResultSet.data("phone")
    vTo="&To=+1"+vSendNumber
     
    vPostFields=vBody+vFrom+vTo
    
    ce.setOpt("POSTFIELDS",vPostFields)
    ce.SetOpt("FILE",cf_1)
    flag_1 = ce.Exec()
    
    flag_1 = cn.ResultSet.NextRow()
    end while
    ce.close()
    cn.Close()
    
    END FUNCTION

    SO what this does is get the phone numbers from the table called sharedto with a column called "phone" and cycle through them sending an SMS to each phone number retrevied by the sql select statement.
    Cool - multiple SMS messaging!

    I have to say this is way less involved than trying to setup pushwoosh for SMS messaging - criminy, you have so many other services involved when you consider iOs and Android - firebase, and on and on.

    In the end, there are a few minor changes in what Larry posted but not much!

    I don't know why, but until I actually used the code Curl-genie myself and compared the results of that with what Larry had I didn't get it!

    Now comes the fun part of tweaking it to get the values from the various fields and a more in-depth SQL select statement to allow message blocking by users...
    Last edited by CharlesParker; 06-18-2018, 01:49 AM.
    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

    Comment


    • #17
      Re: SMS Messaging

      Sorry Charles, I didn't realize that my message had stripped some information.

      I put in \\ before the Quote signs. (Hopefully this one will get through.)

      Glad you were able to sort it out.

      Comment


      • #18
        Re: SMS Messaging

        A few questions...
        If I hard code in my SID and Token into the Xbasic does that expose that information to the web?

        I noticed in working preview that I would get an error saying that the data array was NULL - not everytime though. Since there are only two records and during testing they do not change I was wondering if that error was related to working preview limitations OR if the while statement might need to be written differently. Anyone with expertise in xbasic that can offer any advice on the structure here - please feel free to comment!
        It seems like the "end while" statement might not be in the place in the code perhaps...


        Thanks Larry for what you posted and shared, it really helped me see the way!
        NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

        Comment


        • #19
          Re: SMS Messaging

          I don't think it exposes that info to the web because the xbasic is run on the server, not client side.

          However, you are better off creating a table of constants and storing it there. That way you can use it in other places if you need to without having to put it in more than 1 place.

          Comment


          • #20
            Re: SMS Messaging

            I thought about that but I also thought about the fact that if I make a SQL call to the database that is just another round trip I could eliminate by hardcoding it. If I do have to use it in other places the actual character count of code is negligable and again since it isnt going to change (at least not for now!) I thought hard coding it would be faster without having to hit a database for the info.
            NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

            Comment


            • #21
              Re: SMS Messaging

              Fortunately, in Alpha, you can search for a character string throughout the system, so even if you do have to change it someday, it should be easy to track down all instances.

              Comment


              • #22
                Re: SMS Messaging

                I know this thread is old. I tried both Larry's and Charles's code and did not get a good send. Here is Larry's code modified for my testing. Does anything stand out as a problem?
                Code:
                FUNCTION SendTw AS C (phonenumber AS C )
                'FUNCTION SendTw AS C (vContact_ID AS C )
                
                debug(1)
                '==CONNECTION AND VARS
                'dim cn as SQL::Connection
                dim vHasError as c
                dim cf_1 as extension::CurlFile
                dim flag_1 as l
                dim ce as extension::Curl
                
                if phonenumber = ""
                	vReply = ui_get_text("Send to phone", "Number","")
                	if vReply = ""
                		SendTw = "Cancel"
                		exit function
                	else
                		phonenumber = remspecial(phonenumber)
                	end if
                end if
                
                vHasError = "N"
                
                'cn.open("::name::conn")
                'vselect = "select sid, token, messagefromid, apiurl from twillio"
                'cn.execute(vSelect)
                
                vTwilioURLPre= "https://api.twilio.com/2010-04-01/Accounts/"	'cn.resultset.data("apiurl")
                vSID = [my sid]	'cn.resultset.data("sid")
                vTwilioURL=vTwilioURLPre+vSID+"/Messages"
                vToken = [my token]	'cn.resultset.data("token")
                vPassword=vSID+":"+vToken
                vFromNumber="+19723629267"	'cn.resultset.data("messagefromid")
                vFrom="&From="+vFromNumber
                
                'vSelect = "SELECT Subject, Message FROM Contact_Info where Contact_ID = "+ vContact_id
                'cn.execute(vSelect)
                
                vSubject = ""	'cn.resultset.data("Subject")
                vMessage = "Test message from Twilio."	'cn.resultset.data("Message")
                
                '' I grab all of the recipients phone numbers from the recipients table - so this will send to multiple people.
                'vSelect = "SELECT cell_phone_No_Check FROM Contact_recipients as cr inner join view_people_info as p on p.people_id = cr.people_id where Contact_ID = "+ vContact_id
                'cn.execute(vSelect)
                
                if vSubject <> " " then
                vMessage=vSubject + " : " + vMessage
                end if
                
                ce = extension::Curl.Init()
                ce.setOpt("URL",vTwilioURL)
                ce.setOpt("NOPROGRESS",1)
                ce.setOpt("USERPWD",vPassword)
                ' ce.setOpt("POSTFIELDSIZE_LARGE",85)
                ce.setOpt("USERAGENT","curl/7.34.0")
                ce.setOpt("MAXREDIRS",50)
                ce.setOpt("CAINFO","C:\\Program Files (x86)\\a5V12\\CARoot\\ca-cert.pem")
                ce.setOpt("CAPATH","C:\\Program Files (x86)\\a5V12\\CARoot")
                ce.setOpt("CUSTOMREQUEST","POST")
                ce.setOpt("TCP_KEEPALIVE",1)
                vBody = "Body="+urlencode(vMessage)
                
                'while eval_valid("cn.resultset.data(\"cell_phone_No_Check\")")
                
                vToNumber= phonenumber	'cn.resultset.data("cell_phone_No_Check")
                vTo="&To=+1"+vToNumber
                
                vPostFields=vBody+vTo+vFrom
                
                ce.setOpt("POSTFIELDS",vPostFields)
                ce.SetOpt("FILE",cf_1)
                flag_1 = ce.Exec()
                
                'flag_1 = cn.ResultSet.NextRow()
                
                'end while
                
                ce.close()
                
                sentout:
                
                '' if we made it this far, the email was sent.
                'vUpdate = "update Contact_Info set Sent = 1 where Contact_ID = "+ vcontact_id
                'cn.execute(vUpdate)
                
                errorout:
                
                'cn.close()
                
                'if vHasError = "Y" then
                'save_to_file(vcode, "c:\a5webroot\wtsql\cc\emailstatus.txt")
                'end if
                
                SendTW = ""
                
                END FUNCTION
                Using Alpha's function twilio_send_sms() does work successfully with the same parameters. (although there appears to be a bug if send is not successful - still get a result of .t.).

                Bill.

                Comment


                • #23
                  Re: SMS Messaging

                  My vFromNumber is the ID of the twillio number, not the actual phone number. It's a really long string of characters and numbers, similar to the SID.

                  Comment


                  • #24
                    Re: SMS Messaging

                    Originally posted by Bill Parker View Post

                    Using Alpha's function twilio_send_sms() does work successfully with the same parameters. (although there appears to be a bug if send is not successful - still get a result of .t.).

                    Bill.
                    Alphas function gives you the result as json. You can check the status code. So basically .t. means that you did get the result. You just have to check the result what it means.

                    Comment


                    • #25
                      Re: SMS Messaging

                      Larry,

                      Where did you get that id? From the Twilio dashboard, the phone # is listed, but I don't see where to get the id of the phone #.

                      Comment


                      • #26
                        Re: SMS Messaging

                        Kenneth,

                        I got a similar reply from Selwyn. He said "since twilio is reporting status = 400 you can choose to interpret this as a failure." That seems to imply there are other interpretations? :-(

                        Interestingly, a successful send includes a result field of error_code and error_message. An unsuccessful send does not include those fields, but has a "message" field with the error.

                        Bill.

                        Comment


                        • #27
                          Re: SMS Messaging

                          You want the messaging service, not the phone number. (Each messaging service can have multiple numbers.)

                          Go to the phone numbers list and to the right of each number you will see a link to the messaging service.

                          Click on that to get it's ID.

                          Comment


                          • #28
                            Re: SMS Messaging

                            I'm guessing the problem may be that I am using a trial account currently, unless I am in the wrong place. This is what I see from the dashboard.
                            twilio dashboard.PNG

                            Comment


                            • #29
                              Re: SMS Messaging

                              Click on the … to the left, then select phone numbers.

                              The trial account will have one. Then click on the messaging service.

                              Comment


                              • #30
                                Re: SMS Messaging

                                Thanks. Got the phone number sid into vFromNumber, but ce.exec() still returns .f. I don't see any return message like with alpha's twilio_send_sms(). Not sure where to look next.

                                BTW, Selwyn did agree to modify their function to only return .t. if status field is "queued" or "200". That will better match the Help file doc. I can use Alpha's function, but it bugs me that I can't get this going.

                                Bill.

                                Comment

                                Working...
                                X