Get bot last message
# 🤝help
w
{{event.preview}} allows to get the last message from the user, but how to get the last message from the bot. use case (that is decribed in the docs) : to export conversation data to mixpanel for example, the doc indicates to paste this code in a "before outgoing message" hook :
Copy code
const botAnalyticsData = {
  time: event.createdOn.getTime(), // Mixpanel event datetime
  $insert_id: event.id, // Mixpanel unique event
  distinct_id: event.userId, // Mixpanel preventing duplicates
  bot_id: event.botId,
  conversation_id: event.conversationId,
  payload: event.payload,
  text: event.preview,
  current_flow: event.state.context.currentFlow,
  current_node: event.state.context.currentNode,
  current_card: event.state.context.currentCard,
}
in order to get the last message from the bot. In fact, that retrieves the last message from the user, with {{event.preview}} Maybe i missed something about that !
Okay got it, we can use outgoingEvent.preview
that can be interesting to update this page of the doc i think
but that only works in this hook configuration
b
or you can store your message in temp.response with a custom action
Thats what i do at least, but i let openAI do most of my NLP
w
in the hook code ?
b
Yes, so retrieve the last response from the openAI api, and then store it in temp.response
w
I wasn’t talking about AI response , but bot messages in general
OutgoingEvent.preview works fine in a hook
b
youre right, sorry i read over the hook part. that should work indeed
122 Views