Results 1 to 5 of 5

Thread: SMS messages and emojis

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Castlegar, BC Canada
    Posts
    3,679

    Default SMS messages and emojis

    I am using Chilkat to send and receive SMS messages through Twilio. The code posted at the bottom works great generally, but if the JSON Response "body" has an emoji in it (ie UTF16) the Get ComStringOf returns the message perfectly except for the emoji. I've shown a sample response which has just an emoji (\ud83d\ude01) (smiley face). The first part of chilkat retrieves this properly, but the second stage of pulling out the "message" members changes it to "??". Any thoughts on what I need to do differently to get the actual unicode string out?


    My string sJSONResponse contains the whole response including the body (shown in red):

    {"first_page_uri": "/2010-04-01/Accounts/xxxxxxxxxxxxxxx/Messages.json?PageSize=50&Page=0", "end": 0, "previous_page_uri": null, "messages": [{"body": "\ud83d\ude01", "num_segments": "1", "direction": "inbound", "from": "+16132428528", "to": "+16474902984", "date_updated": "Wed, 08 Jan 2020 14:24:45 +0000", "price": "-0.00750", "error_message": null, "uri": "/2010-04-01/Accounts/xxxxxxxxxxxxxxxx/Messages/SMded9a945ff922cb5f4bc140644810843.json", "account_sid": "xxxxxxxxxxxxxxx", "num_media": "0", "status": "received", "messaging_service_sid": null, "sid": "SMded9a945ff922cb5f4bc140644810843", "date_sent": "Wed, 08 Jan 2020 14:24:45 +0000", "date_created": "Wed, 08 Jan 2020 14:24:44 +0000", "error_code": null, "price_unit": "USD", "api_version": "2010-04-01", "subresource_uris": {"media": "/2010-04-01/Accounts/xxxxxxxxxxxxxx/Messages/SMded9a945ff922cb5f4bc140644810843/Media.json", "feedback": "/2010-04-01/Accounts/xxxxxxxxxxxx/Messages/SMded9a945ff922cb5f4bc140644810843/Feedback.json"}}], "uri": "/2010-04-01/Accounts/xxxxxxxxxxxx/Messages.json?PageSize=50&Page=0", "page_size": 50, "start": 0, "next_page_uri": null, "page": 0}
    but then Get ComStringAs returns "??" instead of "\ud83d\ude01"


    Code:
    Function fGetTwilioMessages Returns tTwilioJSONResponse[]
            tTwilioJSONResponse[] taRet
            Handle hoRest hoCharset hoCharTranslate
            Boolean iBTls
            Integer iPort
            Boolean iBAutoReconnect
            Boolean iSuccess
            String sResponseJson
            String sTemp1 sPrice 
            String sBody
            Boolean bTemp1
            Boolean bIsUnlocked
            Integer iRet
            Handle hoJson
            Integer i 
            Integer iNumEvents
            Boolean bRet
            ////
             
            
        
            //Set Value of oJSONContent to ''
            //  This example requires the Chilkat API to have been previously unlocked.
            //  See Global Unlock Sample for sample code.
            Get pbIsChilKatUnlocked of hAppWS to bIsUnlocked
            
            If (not(bIsUnlocked)) Get fUnlockChilKat to iRet
            Set pbIsChilkatUnlocked of hAppWS to True
            
                
            Get Create (RefClass(cComChilkatRest)) to hoRest
            If (not(IsComObjectCreated(hoRest))) Begin
                Send CreateComObject of hoRest
            End
            
            
            //I've substitued dummy information here as xxxxx and yyyyy
            Get ComSetAuthBasic of hoRest "xxxxxxxxxxxxxx" "yyyyyyyyyyyyy" to iSuccess
              
            //  Connect to the REST server.
            Move True to iBTls
            Move 443 to iPort
            Move True to iBAutoReconnect
            Get ComConnect of hoRest "api.twilio.com" iPort iBTls iBAutoReconnect to iSuccess
            If (iSuccess <> True) Begin
                Get ComLastErrorText of hoRest to sTemp1
                //Showln sTemp1
                //Procedure_Return
                Move 'GSC_X' to taRet[0].sError_Code
                Move sTemp1 to taRet[0].sError_Message
                Function_Return taRet
            End
            
            
            Get ComFullRequestFormURLEncoded of hoRest "GET" "/2010-04-01/Accounts/AC825a727c098ca45b4770735e9822a4be/Messages.json" to sResponseJson
            //At this point sResponseJson has the full unicode string... it is correct
            Get ComLastMethodSuccess of hoRest to bTemp1
            If (bTemp1 <> True) Begin
                Get ComLastErrorText of hoRest to sTemp1
                //Showln sTemp1
                //Procedure_Return
                Move 'GSC_X' to taRet[0].sError_Code
                Move sTemp1 to taRet[0].sError_Message
                Function_Return taRet
            End
        
            //Showln sResponseJson
            //Showln "----"
        
            
            Get Create (RefClass(cComChilkatJsonObject)) to hoJson
            If (not(IsComObjectCreated(hoJson))) Begin
                Send CreateComObject of hoJson
            End
            
            Get ComLoad of hoJson sResponseJson to bRet
            Get ComSizeOfArray of hoJson "messages" to iNumEvents
            Move 0 to i
            While (i < iNumEvents)
                //summary
                Set ComI of hoJson to (i)
                Get ComStringOf of hoJson "messages[i].price" to sPrice
                If (sPrice<>'null') Move sPrice to taRet[i].nPrice
                Get ComStringOf of hoJson "messages[i].direction" to taRet[i].sDirection
                Get ComStringOf of hoJson "messages[i].error_code" to taRet[i].sError_Code
                Get ComStringOf of hoJson "messages[i].error_message" to taRet[i].sError_Message
                Get ComStringOf of hoJson "messages[i].from" to taRet[i].sFrom
                Get ComStringOf of hoJson "messages[i].num_media" to taRet[i].sNum_Media
                Get ComStringOf of hoJson "messages[i].num_segments" to taRet[i].sNum_Segments
                Get ComStringOf of hoJson "messages[i].price_unit" to taRet[i].sPrice_Unit
                Get ComStringOf of hoJson "messages[i].sid" to taRet[i].sSid
                Get ComStringOf of hoJson "messages[i].status" to taRet[i].sStatus
                Get ComStringOf of hoJson "messages[i].to" to taRet[i].sTo
                Get ComStringOf of hoJson "messages[i].body" to taRet[i].sBody
                //The line above now changes any unicode encoding to two ascii characters ('??' in my example)
                
                
                Increment i
            Loop
            
            If (hoRest>0) Send Destroy of hoRest
            If (hoJson>0) Send Destroy of hoJson
            
            Function_Return taRet
          
              //SAMPLE JSON RESPONSE:    
              //{
              //  "sid": "MM97ecfd43e9f24e99b0c2c6ee016949e3",
              //  "date_created": null,
              //  "date_updated": null,
              //  "date_sent": null,
              //  "account_sid": "112e1111e0151133d11112101111d1111",
              //  "to": "+16518675309",
              //  "from": "+15005550006",
              //  "messaging_service_sid": null,
              //  "body": "Sent from your Twilio trial account - Hey Jenny! Good luck on the bar exam!",
              //  "status": "queued",
              //  "num_segments": "1",
              //  "num_media": "0",
              //  "direction": "outbound-api",
              //  "api_version": "2010-04-01",
              //  "price": null,
              //  "price_unit": "USD",
              //  "error_code": null,
              //  "error_message": null,
              //  "uri": "/2010-04-01/Accounts/xxxxxxxxxxxxxxxxxxf07341d3824/Messages/MM97ecfd43e9f24e99b0c2c6ee016949e3.json",
              //  "subresource_uris": {
              //    "media": "/2010-04-01/Accounts/xxxxxxxxxxxxxxxxxxxxx341d3824/Messages/MM97ecfd43e9f24e99b0c2c6ee016949e3/Media.json"
              //  }
        
        End_Function
        
    
    Last edited by Mike Cooper; 9-Jan-2020 at 04:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •