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

Parsing Twilio form application/x-www-urlencoded data

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

    Parsing Twilio form application/x-www-urlencoded data

    Can someone tell me how to (parse) get this data into variables like I might do with json_parse? This is the raw data posted from my twilio voice app. I want to get it into variables and insert the values into my database. Content-type is x-www-form-urlencode to see the POST data from twilio I setup a requestbin at requestbin.com so I could take a look at what is being sent to my page. Now that I see it, I am not sure what to do with it. If it were just json I would use json_parse and use a pointer but I do not know how to consume this. any help would be awesome!
    I am thinking something like application/x-www-urlencoded to json



    Using requestbin to see the data...

    RAW data looks like this:

    Called=%2B15043702624&ToState=LA&CallerCountry=US&Direction=inbound&Timestamp=Tue%2C%2024%20Dec%202019%2022%3A28%3A19%20%2B0000&CallbackSource=call-progress-events&CallerState=LA







    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?"

    #2
    Re: Parsing Twilio form application/x-www-urlencoded data

    Hoping someone has a clue here, it seems like a lot of api's/webhooks POST urlencoded data and this must be something easily parsed into a pointer variable...
    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


      #3
      Re: Parsing Twilio form application/x-www-urlencoded data

      I read on twilio:
      To handle a webhook you only need to build a small web application that can accept the HTTP requests. If you already have a web application set up, handling a webhook is usually as easy as adding a new URL to your application.

      If you don't already have a web application, almost all server-side programming languages offer frameworks to help you build one.
      And - I beleive it. I firmly beleive this can be done with xbasic but where to begin?
      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


        #4
        Re: Parsing Twilio form application/x-www-urlencoded data

        Here is what I see in "requestbin" in other words the data that is being sent FROM twilio. I want to setup an a5w page to insert these values into my database. I can write the sql insert part, I am just not sure how to get these values from the POST into args... Hope this helps someone to point me in the right direction.

        post-data.JPG post-data-raw.JPG
        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


          #5
          Re: Parsing Twilio form application/x-www-urlencoded data

          Just as a side note, I am building a custom phone application to log a phone call with the recording. twilio is sending me the details, once I can upsert them into my database I will be able to track marketing numbers and their ROI for myself and others using my application.
          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


            #6
            Re: Parsing Twilio form application/x-www-urlencoded data

            Obviously this is illegal in EU if this data can be linked to a person. However this may be ok if you have legal agreement with the person whos data you are collecting and then the user has right to see all collected data and the user has to have possibility to delete all data collected from user. If you collect this kind of data in EU and something happens to the data (hacking) you WILL need lot of money...

            Comment


              #7
              Re: Parsing Twilio form application/x-www-urlencoded data

              The process advises the caller that all calls are recorded, in the states this is legal and constitutes agreement by notification. https://www.justia.com/50-state-surv...conversations/
              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


                #8
                Re: Parsing Twilio form application/x-www-urlencoded data

                Well, someone might find this useful. As for one of the callbacks that I want to pull the recording from I am using this xbasic

                dim str as c
                str = "RecordingSource=StartCallRecordingAPI&RecordingSid=RE6da42f4f74a9a898b589f5503117498f&RecordingUrl=https%3A%2F%2Fapi.twilio.com%2F2010-04-01%2FAccounts%2FAC426eebf8206da38a9bf919b1724bc6d0%2FRecordings%2FRE6da42f4f74a9a898b589f5503117498"
                dim rs as c
                rs = ""

                dim st as c
                dim en as c
                st = "="
                en = "&"
                rs = extract_string(str,st,en,3)
                dim myurl as c
                myurl = urldecode(rs)

                I am just testing really but what this does is pull the text from the 3rd start and stop text so I can get the url for the voice recording (and yes i edited the true url value) - finally it decodes the text to make it a "normal" url
                so I think using this method I can get the values I want - again, anyone with an EASY method please let me know!
                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


                  #9
                  Re: Parsing Twilio form application/x-www-urlencoded data

                  As another followup to my own solution/post/question, lol
                  I did get the recording working using an a5w page as the webhook destination.
                  This is the code on the page:

                  Code:
                  <%a5
                  dim str as c = Request.body
                  dim rs as c
                  rs = ""
                  dim st as c
                  dim en as c
                  st = "="
                  en = "&"
                  rs = extract_string(str,st,en,3)
                  dim myurl as c
                  myurl = urldecode(rs)
                  dim mycoid as c = "mycompanyid"
                  dim myuser as c = "[email protected]"
                  
                  	dim cn as sql::Connection
                  	dim result as l = .f.
                  	dim args as sql::arguments
                  		result = cn.open("::Name::Connection1")
                  			if result then
                  		args.Set("url",myurl)
                  		args.Set("coid",mycoid)
                  		args.Set("userid",myuser)
                  
                  
                  
                  			mypostsql = "INSERT INTO alphanwcopro2.company_phonelog SET company_id = :coid, userid = :userid, recording_url = :url"
                  cn.execute(mypostsql,args)			
                  end if
                  cn.close()
                  %>

                  So as I stated in my last post I was able to get the text from the string into an argument and insert the URL of the recorded call into my database. I hope this helps someone in the future working with twilio! Being a complete novice, I was able to figure it out!
                  So once again, Alpha Software gets it done!
                  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


                    #10
                    Re: Parsing Twilio form application/x-www-urlencoded data

                    This isn't really the end though! Twilio is pretty awesome. Using "Twilio Studio" I was able to greet my caller with a message that all calls are recorded and monitored for quality assurance - then through prompts direct callers to the appropriate number if they were looking for something else - then record the call with caller ID, then twilio sends me the webhook and I insert the phone call into the application. What's nice is I can delete the voicemail from my phone knowing I have a copy of the call in my application. from there I can do the usual, create a job & a customer - schedule a job (jim coltz calendar), etc.
                    Pretty cool stuff!

                    Call-Flow.JPG
                    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


                      #11
                      Re: Parsing Twilio form application/x-www-urlencoded data

                      Originally posted by CharlesParker View Post
                      As another followup to my own solution/post/question, lol
                      I did get the recording working using an a5w page as the webhook destination.
                      This is the code on the page:

                      Code:
                      <%a5
                      dim str as c = Request.body
                      dim rs as c
                      rs = ""
                      dim st as c
                      dim en as c
                      st = "="
                      en = "&"
                      rs = extract_string(str,st,en,3)
                      dim myurl as c
                      myurl = urldecode(rs)
                      dim mycoid as c = "mycompanyid"
                      dim myuser as c = "[email protected]"
                      
                      	dim cn as sql::Connection
                      	dim result as l = .f.
                      	dim args as sql::arguments
                      		result = cn.open("::Name::Connection1")
                      			if result then
                      		args.Set("url",myurl)
                      		args.Set("coid",mycoid)
                      		args.Set("userid",myuser)
                      
                      
                      
                      			mypostsql = "INSERT INTO alphanwcopro2.company_phonelog SET company_id = :coid, userid = :userid, recording_url = :url"
                      cn.execute(mypostsql,args)			
                      end if
                      cn.close()
                      %>

                      So as I stated in my last post I was able to get the text from the string into an argument and insert the URL of the recorded call into my database. I hope this helps someone in the future working with twilio! Being a complete novice, I was able to figure it out!
                      So once again, Alpha Software gets it done!
                      Is there any particular reason you want to use arguments in your insert statement here?

                      Comment


                        #12
                        Re: Parsing Twilio form application/x-www-urlencoded data

                        I like arguments...and to be perfectly honest it's the only sure-fire way I know. Any input or criticism is greatly appreciated! I hope this helps someone to build and work with the twilio callbacks in the future even if someone says, hey parker your code is stupid HERE is a much more efficient method! the way I see it we all benefit when we exchange ideas! Feel free to provide a better solution, or a working alternative - I am always glad to hear from experienced devs like you guys here in the forum - many times in my journey I posted my code and someone posted back a more efficient method or voiced concerns in ways I hadn't thought of.
                        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


                          #13
                          Re: Parsing Twilio form application/x-www-urlencoded data

                          Ok, after some testing I found that extracting the string the way I was is setting yourself up for failure and there is a better method to extract the necessary string.
                          Rather than use the "=" sign you should use the value and the equals sign so instead of this:

                          Code:
                          dim st as c
                          dim en as c
                          st = "="
                          en = "&"
                          called = extract_string(str,st,en,1)
                          mycalled = right(called,10)
                          'trims the plus sign and the 1 by counting off ten
                          fmtmycalled  = regex_literal_insert(mycalled,"\([0-9][0-9][0-9]\) [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]")
                          You should use

                          Code:
                          dim st as c
                          dim en as c
                          st = "Called="
                          en = "&"
                          called = extract_string(str,st,en,1)
                          mycalled = right(called,10)
                          'trims the plus sign and the 1 by counting off ten
                          fmtmycalled  = regex_literal_insert(mycalled,"\([0-9][0-9][0-9]\) [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]")
                          by changing the variable st = "=" to "Called="
                          you'll get the first instance of "Called="
                          and returns whats after it
                          The first way just grabs the first "=" sign which if you were looking for the 10th one and the fields changed your code wouldn't pickup the correct value from the string, the second method will only find the value your looking for instead of counting the number of "=" signs - like I said the post from twilio might change as in the case of a forwarded number which adds in an additional number of name/value pairs which then will throw off the count and therefore your result using extract_string


                          So here is the complete actual working code to parse the values from a voice webhook from twilio and insert it into a database using an a5w page as the endpoint:

                          Code:
                          <!DOCTYPE html>
                          <html>
                          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                          <?xml version="1.0"?>
                          <Response/>
                          <body>
                          
                          <%a5
                          
                          
                          dim str as c = Request.body
                          dim called as c
                          dim mycalled as c
                          dim fmtmycalled as c
                          dim callto as c
                          dim myto as c
                          dim fmtmyto as c
                          dim callfrom as c
                          dim trimcallfrom as c
                          dim fmtcallfrom as c
                          dim callsid as c
                          dim name as c
                          dim fmtname as c
                          dim calltost as c 
                          calltost = "To="
                          dim cfst as c
                          cfst = "From="
                          dim callsist as c
                          callsist = "CallSid="
                          dim namest as c
                          namest = "CallerName="
                          
                          dim st as c
                          dim en as c
                          st = "Called="
                          en = "&"
                          called = extract_string(str,st,en,1)
                          mycalled = right(called,10)
                          'trims the plus sign and the 1 by counting off ten
                          fmtmycalled  = regex_literal_insert(mycalled,"\([0-9][0-9][0-9]\) [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]")
                          'formats the phone number I think this is the number that called twilio if it was forwarded or origination
                          
                          
                          
                          callto = extract_string(str,calltost,en,1)
                          myto = right(callto,10)
                          fmtmyto = regex_literal_insert(myto,"\([0-9][0-9][0-9]\) [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]")
                          'formats the phone number this is the twilio tracking number
                          
                          
                          callfrom = extract_string(str,cfst,en,1)
                          trimcallfrom = right(callfrom,10)
                          fmtcallfrom = regex_literal_insert(trimcallfrom,"\([0-9][0-9][0-9]\) [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]")
                          'formats the phone number this is the callers number for callback - this is who called
                          
                          
                          callsid = extract_string(str,callsist,en,1)
                          'this is the call ID used to match up the recording used in the followup webhook for the recording
                          
                          
                          name = extract_string(str,namest,en,1)
                          fmtname = urldecode(name)
                          'this is the callerid for the callers name
                          
                          dim mycoid as c = "504337517323"
                          dim myuser as c = "[email protected]"
                          
                          	dim cn as sql::Connection
                          	dim result as l = .f.
                          	dim args as sql::arguments
                          		result = cn.open("::Name::Connection1")
                          			if result then
                          		args.Set("called",fmtmycalled)
                          		args.Set("to",fmtmyto)
                          		args.Set("from",fmtcallfrom)
                          		args.Set("callsid",callsid)
                          		args.Set("name",fmtname)
                          
                          		args.Set("coid",mycoid)
                          		args.Set("userid",myuser)
                          
                          
                          
                          			mypostsql = "INSERT INTO alphanwcopro2.company_phonelog SET company_id = :coid, userid = :userid, callsid = :callsid, Company_Name = :name, Full_Name = :name, Call_Back = :from, called = :called, Called_From = :from"
                          cn.execute(mypostsql,args)			
                          end if
                          cn.close()
                          %>
                          </body></html>

                          I could simplify the code in many places, especially in the dimming process and probably will but this just to show how it can be done. I am sure there's a lot of you much smarter than me who could take that string get an array and do the insert in a much more simplistic manner - feel free to show off!
                          Either way, it's working and only took me a few days, lol to figure it out!


                          Also just to explainify further the above code is the FIRST webhook which I use to INSERT the call info into my database. The second one which always happens about 2 seconds after provides the recording from the "CallSid" which is how you match the two. So, as I said - the first one INSERTS the call with the callsid. The second webhook posts the recorded call info to another a5w page, and I take that and UPDATE the previously inserted data using this code:

                          Code:
                          <%a5
                          dim str as c = Request.body
                          dim rs as c
                          rs = ""
                          dim st as c
                          dim en as c
                          st = "RecordingUrl="
                          en = "&"
                          rs = extract_string(str,st,en,1)
                          dim myurl as c
                          myurl = urldecode(rs)
                          
                          
                          dim callsid as c
                          dim callst as c
                          callst = "CallSid="
                          callsid = extract_string(str,callst,en,1)
                          'this is the call ID used to match up the recording used in the followup webhook for the recording
                          
                          	dim cn as sql::Connection
                          	dim result as l = .f.
                          	dim args as sql::arguments
                          		result = cn.open("::Name::Connection1")
                          			if result then
                          		args.Set("url",myurl)
                          		args.Set("callsid",callsid)
                          
                          
                          
                          
                          			mypostsql = "UPDATE alphanwcopro2.company_phonelog SET recording_url = :url WHERE callsid = :callsid"
                          cn.execute(mypostsql,args)			
                          end if
                          cn.close()
                          %>

                          So anyways - it works! Hope it helps
                          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

                          Working...
                          X