Ruby on Rails integration
1. Add the snippet to your layout
Use the async loader from the docs home.
2. Server-side user hash
# app/helpers/application_helper.rb
def rokochat_user_hash(user_id)
OpenSSL::HMAC.hexdigest("SHA256", ENV["ROKOCHAT_IDENTITY_SECRET"], user_id.to_s)
end3. Call identify() in the browser
Rokochat.identify({
id: user.id,
user_hash: userHash,
email: user.email,
name: user.name,
});<script>
Rokochat.identify({
id: '<%= current_user.id %>',
user_hash: '<%= rokochat_user_hash(current_user.id) %>',
email: '<%= current_user.email %>',
});
</script>Always call Rokochat.logout() when the user signs out.