Class: FlowChat::Messenger::Client
- Inherits:
-
Object
- Object
- FlowChat::Messenger::Client
- Includes:
- Instrumentation
- Defined in:
- lib/flow_chat/messenger/client.rb
Direct Known Subclasses
Constant Summary
Constants included from Instrumentation
Instrumentation::DELIVERED_MESSAGE_ID_KEY, Instrumentation::DELIVERY_DURATION_KEY
Instance Method Summary collapse
-
#indicate_typing(recipient_id) ⇒ Object
Shows the person a typing bubble while a turn is being worked out.
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #send_message(recipient_id, prompt, choices: nil, media: nil, tag: nil) ⇒ Object
- #send_text(recipient_id, text, tag: nil) ⇒ Object
-
#upload_media(url, type: :image) ⇒ Object
Uploads a file for reuse and returns the id Meta assigned it.
Methods included from Instrumentation
#elapsed_ms_since, #inbound_message?, #instrument, instrument, #platform_message_id_from, report_api_error, #report_delivery_failure, #report_delivery_success, #report_to_app, #report_to_subscribers
Constructor Details
Instance Method Details
#indicate_typing(recipient_id) ⇒ Object
Shows the person a typing bubble while a turn is being worked out.
Meta clears it when the next message arrives or after about twenty seconds, whichever comes first, so a caller holding one open for longer has to repeat it.
Inherited by Instagram rather than overridden there. Meta documents sender actions under the Messenger Platform and lists only react and unreact for Instagram, but an Instagram send of typing_on is accepted and answered with the recipient id, same as Messenger. Confirmed against a live account, since the reference does not settle it.
50 51 52 |
# File 'lib/flow_chat/messenger/client.rb', line 50 def indicate_typing(recipient_id) post_json(@config., {recipient: {id: recipient_id}, sender_action: "typing_on"}) end |
#send_message(recipient_id, prompt, choices: nil, media: nil, tag: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flow_chat/messenger/client.rb', line 22 def (recipient_id, prompt, choices: nil, media: nil, tag: nil) response = renderer_class.new(prompt, choices: choices, media: media).render type, content, = response # MESSAGE_SENT is instrumented by the gateway, not here. This wrapped # the send in its own instrument block, and ActiveSupport::Notifications # publishes a block event once the block returns whatever it returned - # so the event fired even when the send had failed and this method was # about to answer nil, and fired a second time when the gateway # instrumented the same send. deliver(recipient_id, type, content, , tag) end |
#send_text(recipient_id, text, tag: nil) ⇒ Object
35 36 37 |
# File 'lib/flow_chat/messenger/client.rb', line 35 def send_text(recipient_id, text, tag: nil) (recipient_id, text, tag: tag) end |
#upload_media(url, type: :image) ⇒ Object
Uploads a file for reuse and returns the id Meta assigned it.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flow_chat/messenger/client.rb', line 55 def upload_media(url, type: :image) payload = { message: { attachment: { type: type.to_s, payload: {url: url, is_reusable: true} } } } result = post_json(@config., payload) result && result["attachment_id"] end |