lib/messenger/bot/transmitter.rb in messenger-bot-1.0.2 vs lib/messenger/bot/transmitter.rb in messenger-bot-1.0.3
- old
+ new
@@ -4,21 +4,31 @@
def initialize(sender)
@sender_id = sender
end
def reply(data)
- data = {
- recipient: {
- id: @sender_id
- },
- message: data
- }
+ data = init_data.merge({ message: data })
Messenger::Bot::Request.post("https://graph.facebook.com/v2.6/me/messages?access_token=#{Messenger::Bot::Config.access_token}", data)
end
- def get_profile(fields = nil)
+ def get_profile(fields=nil)
fields ||= [:locale, :timezone, :gender, :first_name, :last_name, :profile_pic]
Messenger::Bot::Request.get("https://graph.facebook.com/v2.6/#{@sender_id}?fields=#{fields.join(",")}&access_token=#{Messenger::Bot::Config.access_token}")
+ end
+
+ def action(sender_action=true)
+ data = init_data.merge({ sender_action: sender_action ? "typing_on" : "typing_off" })
+ Messenger::Bot::Request.post("https://graph.facebook.com/v2.6/me/messages?access_token=#{Messenger::Bot::Config.access_token}", data)
+ end
+
+ private
+
+ def init_data
+ {
+ recipient: {
+ id: @sender_id
+ }
+ }
end
end
end
end