X
X
Xip
Search…
Alpha Ordinal Matcher
Alpha ordinals are a way of providing "quick replies" for messaging services that do not support them natively, such as SMS and Whatsapp. With handle_message, they are supported directly.

Example

Imagine you send a user this reply:
1
What's your favorite color?
2
3
Reply with:
4
"A" for Red
5
"B" for Blue
6
"C" for Green
7
"D" for Yellow
Copied!
Xip's Twilio component can automatically generate these for you. This is covered in depth in the YAML Replies docs.
The corresponding handle_message method would look like this:
1
def get_response
2
handle_message(
3
'Red' => proc { current_user.update_attributes!(favorite_color: 'red') },
4
'Blue' => proc { current_user.update_attributes!(favorite_color: 'blue') },
5
'Green' => proc { current_user.update_attributes!(favorite_color: 'green') },
6
'Yellow' => proc { current_user.update_attributes!(favorite_color: 'yellow') }
7
)
8
end
Copied!
With alpha ordinals, if a user types "C", then the Green match arm is automatically selected since it is the 3rd match expression (Line 5) specified in handle_message. Similarly, the user could still reply with "green" directly and that will also match the 3rd match expression (Line 5).
If a user were to type, "E", then Xip will still raise a Xip::Errors::UnrecognizedMessage exception.
Copy link
Contents
Example