Jinja snippets - Chat history from certainly.transcript reserved variable

Jinja snippets to render a conversation transcript from certainly.transcript reserved variable

 

Often, we want to pass a chat history as part of a support ticket. For that, we can use {{ certainly.transcript }} reserved variable.

Another option is to use the Chat History Webhook, which will also allow to show what suggested replies were clicked by a user and cards displayed by the bot.

Below are examples of Jinja code to produce HTML versions of the chat history that support showing uploaded images

HTML version

This version of the chat transcript has all users' messages highlighted in bold, making it easier to read.

HTML version looks like this:

Use the Jinja code below in the Custom Variable mapping of the Webhook:

{# Chat history as HTML -#}
{% for m in certainly.transcript -%}
{% if m.get("text") and m.text != "…"-%}
{% set txt = m.text|striptags -%}
{% set txt="
Attachment" if txt.startswith("http") else txt -%}
{% set txt = "<b>"~txt~"</b>" if "HUMAN" in m.from.upper() else txt -%}
{{ m.from.upper() }}: {{ txt|safe }}<br>
{% endif -%}{# print message -#}
{% endfor -%}