Email callback

Intro

We offer you the ability to send all automatic emails meant for contacts to your own server via a callback URL, instead of sending the email through our email infrastructure. By sending the emails via your own email server infrastructure or helpdesk system, you get total control over the sender identity and the return path.

Enable email callback URL

  1. Go to the email callback API settings in the widget editor under Chat > Advanced.
  1. Check the Custom email API box
Image without caption

Request documentation

Type
Value
Description
Request Method
POST
Request Header
API-SECURITY-TOKEN
Contains your custom security token
Request Body
JSON

JSON body

Name
Type
Description
html
String
HTML version of the email body
receiver
String
Email address of the recipient
subject
String
Subject of the email
text
String
Raw text email
email_type
String
The type of email Userlike sends, it’s either "transcript" or "reauth"
context
String
Important information that the email contains. Each email_type has its own context, scroll down to Transcript contextand Reauth context to learn more
An example of a message object:
javascript
{ "body": "Hi there! How do I install this?", "conversation": { "id": 8982 }, "conversation_id": 8982, "display_name": "Contact", "event": null, "id": "8982.12509.48079", "marked_read_contact": true, "marked_read_operator": true, "msgid": "8982.12509.48079", "name": "Contact", "operator_display_name": "", "operator_id": null, "operator_name": "", "part_id": 12509, "reference": null, "sender": { "id": 5882, "type": "contact" }, "sent_at": "2020-07-09T12:18:05.220985Z", "sent_at_time": "12:18:05.220985", "state": { "error_code": null, "message": "Read by user", "type": 4 }, "type": "message", "url": null }

Transcript context

Transcript emails contain all messages sent during a Conversation as well as survey answers, feedback, ratings and other Conversation events. Their email_type is set to "transcript".
Name
Type
Description
messages
Array
An array of all messages sent during a Conversation. Each message is an object
conversation_url
String
A link that brings your contacts back to the conversation. Note that the link can be missing if no inbound URL is defined in the Widget’s settings.

Reauth context

Reauth emails contain a link and a token with which contacts can authenticate themselves.
Name
Type
Description
reauth_link
String
A link that authenticates your contacts when they click on it. Note that the link can be missing if no inbound URL is defined in the Widget’s settings.
reauth_token
String
A token that contacts can enter in the Widget to authenticate, for example when no reauth link is displayed

Python example using the Flask framework

javascript
from flask import Flask, request import json from flask_mail import Mail, Message app = Flask(name) Example with Gmail server app.config['MAIL_SERVER']='smtp.gmail.com' app.config['MAIL_PORT'] = 465 app.config['MAIL_USERNAME'] = 'your-email-address@gmail.com' app.config['MAIL_PASSWORD'] = '*****' app.config['MAIL_USE_TLS'] = False app.config['MAIL_USE_SSL'] = True mail = Mail(app) @app.route('/email', methods=['POST']) def email_callback(): if len(request.data) > 0: data = json.loads(request.data) email_contact = str(data["receiver"]) email_subject = str(data["subject"]) msg = Message(email_subject, sender = 'your-email-address@gmail.com', recipients = [email_contact]) msg.body = data["text"] msg.html = data["html"] mail.send(msg) return "E-mail sent" else: return "Connected" if == 'main': app.run(port=8000, debug=True)