-1

I'm using gem facebook-messenger

Send to Facebook

When the human clicks the Send to Messenger button embedded on a website, you will receive an optin event.

Bot.on :optin do |optin|
  optin.sender    # => { 'id' => '1008372609250235' }
  optin.recipient # => { 'id' => '2015573629214912' }
  optin.sent_at   # => 2016-04-22 21:30:36 +0200
  optin.ref       # => 'CONTACT_SKYNET'

  optin.reply(text: 'Ah, human!')
end


<div class="fb-send-to-messenger" 
  messenger_app_id="<APP_ID>" 
  page_id="PAGE_ID" 
  data-ref="<PASS_THROUGH_PARAM>" 
  color="<blue | white>" 
  size="<standard | large | xlarge>">
</div>

WHEN I tried to simple string to data-ref, it works. BUT putting a url (http://asdasda/asdas/sad?/asd..) DOESN'T WORKED

mikdiet
  • 9,859
  • 8
  • 59
  • 68
aldrien.h
  • 3,437
  • 2
  • 30
  • 52

1 Answers1

0

I found out that data-ref does not accept special character (e.g. !@#$%^&*()|...,

thus encoding and decoding url will not work. Since e.g encoded/decoded url contains special characters like %.

For now, just to make my function work, what I did is make a helper method that replaces special chars.

def parse_product_url(url)
  url.gsub('?', 'QMARK').gsub('&', 'AND').gsub('//', '')
end

And do that in-reverse in Bot..reply argument.

aldrien.h
  • 3,437
  • 2
  • 30
  • 52