Prefill user data

How does it work?

If your customers are logged in to your website or app, you can prefill their name and email into the Happi widget, so they don’t need to complete this step and can focus on sending a message easily.

Using the widget config item customerData, you can passed in a signed token that represents your customers name and email. The reason we use a signed token, is so that it cannot be tampered with.

Creating the signed token

For the creation of tokens we use the widely adopted JWT standard. If you are unfamiliar you should check out the JWT website, as they have libraries available for most programming languages and frameworks.

To sign a JWT you need to have a common shared secret. You can find your shared secret in the widget settings page.

# Example using Ruby and 'jwt' gem
payload = {
  # Required fields
  first_name: "Jenifer",
  last_name: "Jackson",
  email: "jenifer.jackson@aol.im",

  # Optional fields
  company: "ACME Corp",
  phone: "+1 123 555 4356",
  country_code: "US",
  location: "New York City"
}

# Below string gets passed into Happi.init as `customerData`
customer_data = JWT.encode(payload, "your-shared-secret", "HS512")

That’s it! Now the widget will use the data you have passed in and your customer can quickly send a message.