davidmann4 / botstack

rapid chatbot development with ruby on rails
127 stars 23 forks source link

Best way to write a bubble? #21

Open davidmann4 opened 7 years ago

davidmann4 commented 7 years ago

@ramonh I am thinking of the best way of defining bubbles with code: spring_bot_for_messenger_1-xlarge_trans muac98d-ja8s9oi1lbgosvcxqla4yaqscerh0ndk4bq

send_bubble "http://image.com/image.png \n HEADLINE \n subheadline "
#or something like this?
send_bubble [{image: "http://", headline: "headline", description: "description"}]

also you can add buttons to them - hmm

another aproach would be content based:

send_bubble_websites --> list of urls, bots get title of websites and preview images etc ...

I am curious what you think about this topic!

davidmann4 commented 7 years ago

also we need a smart way to handle button clicks ...hmmm

mraaroncruz commented 7 years ago

The way button clicks (aka. postbacks) are handled in other frameworks is with a postback:MYPOSTBACK handler at the message boundaries or in the state machine.

The messenger term for bubbles is Generic Templates. Bubbles may be misleading if you go with it. I thought you meant this https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions

bussi, aaron

mraaroncruz commented 7 years ago

I like the second option with the hash. Good question about the buttons though.

They deserve their own type. Maybe you should just wrap them and make a couple different types.

Botstack::URLButton # or Botstack::Button::URL
Botstack::PostbackButton # or Botstack::Button::Postback

button = Botstack::Button::URL.new(title: "View Product", value: "http://example.com/peters_hat.jpg")

template = Botstack::ButtonTemplate.new(message: "Choose something already!", buttons: [button])

=begin
Outputs
 {"message":{
    "attachment":{
      "type":"template",
      "payload":{
        "template_type":"button",
        "text":"Choose something already!",
        "buttons":[
          {
            "type":"web_url",
            "url":"http://example.com/peters_hat.jpg",
            "title":"View Product"
          }
        ]
      }
    }
  }}
=end

Downside being you'd need to define the buttons beforehand to send into reply_button but the method signature could be something like reply_button(message, buttons)

If you were so inclined, you could even write button factory methods like

def make_url_button(text, url)
# and
def make_postback_button(text, postback)