X
X
Xip
Search…
Available Data
Within each controller action, you have access to a few objects containing information about the session and the received message.
Other Xip components might make additional data available (e.g., sentiment analysis, etc).

current_message

The current message being processed is available via current_message. This is a Xip::ServiceMessage object. It has a few important methods:
sender_id: The ID of the user sending the message. This will vary based on the message service component. This is also the ID that will be used as the user's session ID.
target_id: The ID of the target. This will vary based on the service sending the message, but for Facebook it will be the page_id of the Facebook page receiving the message and for SMS will be the number receiving the SMS message. For other services, this may be nil.
timestamp: Ruby DateTime object containing the timestamp of when the message was transmitted. This might differ from the current time.
service: String indicating the message service from where the message originated (i.e., facebook, or twilio).
message: String of the message contents.
payload: This will vary per message service component.
nlp_result: The raw result of the NLP performed on this message. This will vary per NLP component.
catch_all_reason: This is a hash that contains two keys: :err and :err_msg. The :err key is a string of the exception class that was raised and the :err_msg is the message associated with that exception. See Catch-All Reasons for more info.
location: This will vary per message service component.
attachments: This will vary per message service component.
referral: This will vary per message service component.

current_session

The user's session is accessible via current_session. This is a Xip::Session object. It has a few important methods:
flow_string: Returns the name of the flow.
state_string: Returns the name of the state.
to_s: Returns the session canonical session slug string.
current_session + 2.states: Returns a new session object 2 states after the current state. If we've exceeded the last state in flow (as defined in the FlowMap), the last state is returned.
current_session - 2.states: Returns a new session object 2 states before the current state. If we've exceeded the first state in the flow (as defined in the FlowMap), the first state is returned.
==: Compare two sessions and returns true if they point to the same flow and state and false if they do not.
Use the session arithmetic operators (+ and -) sparingly. They are primarily designed for use in CatchAlls when a fails_to state has not been specified.

current_service

Returns a string indicating the message platform from where the message originated (i.e., facebook, or twilio).
This is an alias of current_message.service

current_session_id

Returns the session ID. This will vary by message service, but for Facebook Messenger this will be the user's PSID and for SMS and Whatsapp this will be the user's phone number in E.164 format.
This is an alias of current_message.sender_id

has_location?

Returns true or false depending on whether or not the current_message contains location data.

has_attachments?

Returns true or false depending on whether or not the current_message contains file or media attachments.
Last modified 9mo ago