-
Notifications
You must be signed in to change notification settings - Fork 12
Response types
Matúš Žilinec edited this page Jun 22, 2018
·
5 revisions
In addition to sending plain text, Golem supports multiple message and media templates. These are based on Facebook's Messenger API, but will work on other platforms as well.
What you can send:
- Text message (text + buttons + quick replies)
- Horizontal list of items (or Generic template message)
- Vertical list of items (or List template)
- Image
- Audio
First, import golem.core.responses.*
.
You can also check package golem.core.responses.
# can be defined directly as string
message = "Hi :) How can I help you?"
# or as a TextMessage (this way we can add buttons and quick replies)
message = TextMessage("Hi :) How can I help you?")
message = TextMessage("Hi :) How can I help you?")
# Open a webpage
message.add_button(LinkButton(title='Example', url='http://example.com'))
# Or send payload - add entities to the context
message.add_button(PayloadButton(title='Suggestions', payload={'query':{'value':'concert', 'metadata' : { ... }}}))
# Entity values can be also passed directly (without the dict wrapper):
# The '_state' entity is used to move to a different state
message.add_button(PayloadButton(title='Suggestions', payload={'_state':'faq.root:accept'}))
message = TextMessage("Hi :) How can I help you?")
# With payload, when clicked, behaves just like a button
message.add_quick_reply(QuickReply(title='Top events', payload={'intent':'search'}))
# Or without payload to be parsed as text
message.add_quick_reply(QuickReply(title='Weather'))
carousel = GenericTemplateMessage()
# Element with image (full-sized image is downloaded!)
element = carousel.create_element(title='Required title', subtitle='Optional subtitle', image_url='Optional image url')
# Add button to element just like to a text message
element.create_button(title='Read article', url='http://example.com')
message = AttachmentMessage(attachment_type='image', url='http://example.com/image.jpg')