Android Question [SOLVED]Put Smileys on text notifications

dibesw

Active Member
Licensed User
Longtime User
I regularly use the push notifications feature through Firebase and I use HTTP POST for send.
Does anyone know how to insert smileys into the notification text?

What text do I need to enter to display the smileys? (in PostDATA)

Thanks in advance to anyone who wants to help me.

1702388215578.jpg


ACCESS code for send:
Public Sub notifica_firebase(TITOLO As String, testonotif As String, IMAGEURL As String, ToTopics As String)
    On Error GoTo NOINTERNET
    Dim sURL As String
    Dim PostData As String
    'sURL = "https://fcm.googleapis.com/fcm/send"
    sURL = "https://fcm.googleapis.com/v1/projects/notifiche-da-studio/messages:send"
    Dim objXMLHTTP As MSXML2.ServerXMLHTTP
    Set objXMLHTTP = New MSXML2.ServerXMLHTTP

    PostData = "{""message"":{" & _
      """token"":""" & ToTopics & """," & _
      """notification"":{" & _
        """body"":""" & testonotif & """," & _
        """title"":""" & TITOLO & """," & _
        """image"":""" & IMAGEURL & """" & _
      "}}}"

    With objXMLHTTP
       .Open "POST", sURL, False
       .SetRequestHeader "Content-Type", "application/json"
       .SetRequestHeader "Authorization", strHeaders
       .Send (PostData)
    End With
    Response = objXMLHTTP.ResponseText
         freeappo = FreeFile
         Open "c:\infostudio\notifica.txt" For Output As #freeappo
         Write #freeappo, objXMLHTTP.ResponseText
         Close #freeappo
    Exit Sub
NOINTERNET:
    DoCmd.Hourglass False
    MsgBox "CONTROLLARE LA CONNESSIONE AD INTERNET " & err.Description, vbCritical
End Sub

I tried to put this unicode 😀 in Body of PostDATA but not work

PostDATA="{""message"":{""token"":""eOvp_BlbQSWIiklmR5kKX5:APA....................................................h2PYqHDhPUhB3KMI9wAYrWnZIWDUw6Z9TnPVHGBmL-VjRyrZtk3AofJ-GkI83-XUfqz1PJ7rpj67ZRX-rey35Opn4p_ifx-cI"",""notification"":{""body"":""😀"",""title"":""LE ANNOTAZIONI DI DOMANI"",""image"":""http://www.xxxxxxxxx.net/img/note4.png""}}}"
 
Last edited:

Sandman

Expert
Licensed User
Longtime User
It seems XenForo perhaps changes that to an embedded image, which isn't what I wanted.

If I do the above and paste it into a simple Notepad-like app on my desktop, this is what I get:
1702396370964.png
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
I tried to do so and work if past in notepad, but when copy (past) in my Access application the result is "?"
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
Use Bytes (UTF-8) notation from this table:
https://apps.timwhitlock.info/emoji/tables/unicode
'x' signs are not necessary, e.g: for ? use \F0\9F\98\81
It works for me for Telegram bot notifications.

Regards, G.
Thanks for your replace, I tried various ways but the problem is that I can't understand out how to convert UTF-8 to my POST string.
My POST string is this
"{""message"":{""token"":""eOvp_BlbQSWIiklmR5kKX5:APA91bH..........................................2PYqHDhPUhB3KMI9wAYrWnZIWDUw6Z9TnPVHGBmL-VjRyrZtk3AofJ-GkI83-XUfqz1PJ7rpj67ZRX-rey35Opn4p_ifx-cI"",""notification"":{""body"":??????,""title"":""LE ANNOTAZIONI DI DOMANI"",""image"":""http://www.xxxxxx.net/img/note4.png""}}}"

how can I put smileys instead of ??????

I found this but I don't know how to put "b" in the POST

B4X:
    Dim b() As Byte
    b = Utf8BytesFromString("F0 9F 98 81")
   
Public Function Utf8BytesFromString(strInput As String) As Byte()
    Dim nBytes As Long
    Dim abBuffer() As Byte
    ' Catch empty or null input string
    Utf8BytesFromString = vbNullString
    If Len(strInput) < 1 Then Exit Function
    ' Get length in bytes *including* terminating null
    nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, 0&, 0&, 0&, 0&)
    ' We don't want the terminating null in our byte array, so ask for `nBytes-1` bytes
    ReDim abBuffer(nBytes - 2)  ' NB ReDim with one less byte than you need
    nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, ByVal VarPtr(abBuffer(0)), nBytes - 1, 0&, 0&)
    Utf8BytesFromString = abBuffer
End Function
 
Last edited:
Upvote 0

DitoNet

Member
Licensed User
Replace '??????' with '\F0\9F\98\81'.
In the meantime I found other possible solution.
Build your POST string using Smart String Literals and you can put smileys directly into that string.
e.g.:
B4X:
$"/sendMessage?chat_id=123456789&text=?&parse_mode=HTML"$
Works perfectly with my Telegram bot.

G.
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
I solved
Thank you Sandman and DitoNet who gave me the right advice
Right POST is

{"message":{"token":"eOvp_BlbQSWIiklmR5kKX5:APA9.........................................................YqHDhPUhB3KMI9wAYrWnZIWDUw6Z9TnPVHGBmL-VjRyrZtk3AofJ-GkI83-XUfqz1PJ7rpj67ZRX-rey35Opn4p_ifx-cI","notification":{"body":"\u260A","title":"LE ANNOTAZIONI DI DOMANI","image":"http://www.xxxxxxxxx.net/img/note4.png"}}}

I can't use all the emoji; for example \u1F33D doesn't work (because it starts with "u1")
(at least for me)
 
Upvote 0
Top