Tawk.to Hash code

Hey all!
I have decided to use Tawk.to live chat on my web app. I have it working as expected triggering from a button. However, the live chat is only on user logged in pages. So I would like to pass the name and email of that user to the chat so I can quickly identify them and provide assistance. Below is the code I thought would work to get the hash and the code they suggest using in straight php.

Any thoughts on why this code won’t work. I have it outputting to a text area on my page and it just shows blank. When I remove the hash bit it shows everything as it should.

// What I am trying
Var hashValue As String
dim key as string = "thekeyprovided"
dim value as string = Session.Email
hashValue = Crypto.HMAC(key, value, Crypto.HashAlgorithms.SHA256)

// What they suggest
<?php echo hash_hmac(“sha256″,”visitor@email.com”,”your-api-key”); ?>

When I comment out the hash bit and replace hashValue in hash : area with just “a” string it shows fine. But doesnt pass the values (understandably). Otherwise this is blank.

Here is the full code on the text area opening event handler.

'Var hashValue As String
'
'dim key as string = "myprovidedkey"
'
'dim value as string = Session.Email
'
'hashValue = Crypto.HMAC(key, value, Crypto.HashAlgorithms.SHA256)


Me.Text = "var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(); "  + EndOfLine
Me.Text = Me.Text + "Tawk_API.visitor = {"  + EndOfLine
Me.Text = Me.Text +"name : '" + Session.Login + "',"  + EndOfLine
Me.Text = Me.Text +"email : '" + Session.Email + "',"  + EndOfLine
Me.Text = Me.Text +"hash : '" + "a" + "'"  + EndOfLine
Me.Text = Me.Text +"};"  + EndOfLine
Me.Text = Me.Text +"(function(){"  + EndOfLine
Me.Text = Me.Text +"var s1=document.createElement(""script""),s0=document.getElementsByTagName(""script"")[0];"  + EndOfLine
Me.Text = Me.Text +"s1.async=true;"  + EndOfLine
Me.Text = Me.Text +"s1.src='https://embed.tawk.to/6386432bdaff0e1306da13c1/XXXXXXX';"  + EndOfLine
Me.Text = Me.Text +"s1.charset='UTF-8';"  + EndOfLine
Me.Text = Me.Text +"s1.setAttribute('crossorigin','*');"  + EndOfLine
Me.Text = Me.Text +"s0.parentNode.insertBefore(s1,s0);"  + EndOfLine
Me.Text = Me.Text +"})();"

Self.ExecuteJavaScript(Me.Text)

Your hash code produces the same results, but Xojo returns raw bytes while PHP returns a hex-encoded string.

To get them to match exactly, add this:

hashValue = EncodeHex( hashValue ).Lowercase
2 Likes