Write as an agent
With Fernand's widget, you can write messages that appears to be coming from your team - or from our automated messaging (with a "flash" avatar).
This is easily done by calling the Fernand widget with the "write" parameter, and with the second parameter being an object that will contain the following required parameters:
message
- The message to writehash
- The message, hashed using the key provided in the settings
You can also pass the following optional parameters:
conversation
- By default, the current conversation will be used, and a new conversation will be created if no current conversation is set. You can either pass:current
- To write in the current conversation (defaults)new
- To write in a new conversation${conversation_id}
- The conversation ID you want to write to
agent
- The agent's email, but hashed using the SHA256 algorithm, to avoid leaking your private email to the external world.callback
- A function that will be called once the message was sent to the user. The function will have one parameter given: the conversation ID, in order for you to write other messages in the same thread.
Here's a custom implementation:
Fernand('write', {
message: 'Hi! Do you need any help?',
hash: '2cd7c249f655f1ef3682f480aae72a59387772431f176b97996a2cc4864857db',
agent: '8ebdca5f696088f694d641a1276ac8c7b9ad526cc45a8820ae19ce2704efb4a7',
conversation: 'new',
callback: (convId) => {
setTimeout(() => {
Fernand('write', {
message: 'Feel free to respond if you need anything',
hash: 'e633d46747e8b5de99dbfa584face65f5bd93540d37ed7da84e09c280522d6cc',
agent: '8ebdca5f696088f694d641a1276ac8c7b9ad526cc45a8820ae19ce2704efb4a7',
conversation: convId
})
}, 2500)
}
})
Why hashing the message
It is required to provide a hashed version of the message, by using the HMAC and SHA256 hashing algorithm, like explained on Authenticating users.
On our side, we will hash your message in the same way, using your chat widget secure key, and will compare that generated hash with your provided hash. If it doesn't match, the message will not be displayed to your user.
By validating the hash, we ensure that the person behind writing the message do have the secure key in their possession. Hopefully it will be only you.
The reason we need to do that, is to ensure that not everyone is able to write a message that looks like coming from one of your agent.
Imagine the case where we would not require this security measure; A visitor could open the developer console, and write a message, saying it comes from your CEO as the agent, and saying the CEO offer 12 months for free. That's not great for business !
For this reason, we need to ensure the message is truly originating from your organization, and the only way to do that is by hashing the message with the secret key.
Optional parameter
The call to Fernand('write', { ... })
accepts a third parameter, a boolean, that will open the chat widget if the widget is not already open and if the parameter is set to true
.
By default, the widget stays closed (like if you were to pass the parameter false
), but you can set it to true
and the widget will open automatically if it's not already open.
If the widget is closed but a new message arrive, a small tooltip will appear on top of the widget's icon, containing your message.
Clicking on it will open the conversation in question.