Class: FlowChat::Telegram::Gateway::BotApi

Inherits:
Object
  • Object
show all
Includes:
GatewayAsyncSupport, Instrumentation
Defined in:
lib/flow_chat/telegram/gateway/bot_api.rb

Instance Attribute Summary collapse

Attributes included from GatewayAsyncSupport

#controller

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GatewayAsyncSupport

#async_supported?, #enqueue_async_job, #extract_body_for_background, #extract_headers_for_background, #extract_host, #extract_path, #extract_remote_ip, #in_background?, #should_enqueue_async?

Methods included from Instrumentation

#instrument, instrument, report_api_error

Constructor Details

#initialize(app, config = nil) ⇒ BotApi

Returns a new instance of BotApi.



14
15
16
17
18
19
20
# File 'lib/flow_chat/telegram/gateway/bot_api.rb', line 14

def initialize(app, config = nil)
  @app = app
  @config = config || FlowChat::Telegram::Configuration.from_credentials
  @client = FlowChat::Telegram::Client.new(@config)

  FlowChat.logger.info { "BotApi: Initialized Telegram Bot API gateway" }
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



12
13
14
# File 'lib/flow_chat/telegram/gateway/bot_api.rb', line 12

def client
  @client
end

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/flow_chat/telegram/gateway/bot_api.rb', line 12

def context
  @context
end

Class Method Details

.configure_middleware_stack(builder, custom_middleware) ⇒ Object

Platform-specific middleware configuration



44
45
46
47
48
# File 'lib/flow_chat/telegram/gateway/bot_api.rb', line 44

def self.configure_middleware_stack(builder, custom_middleware)
  FlowChat.logger.debug { "BotApi: Configuring Telegram middleware stack" }
  builder.use custom_middleware
  builder.use FlowChat::Telegram::Middleware::ChoiceMapper
end

Instance Method Details

#call(context) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/flow_chat/telegram/gateway/bot_api.rb', line 22

def call(context)
  @context = context
  @controller = context.controller
  request = @controller.request

  FlowChat.logger.debug {
    "BotApi: Processing #{begin
      request.request_method
    rescue
      "POST"
    end} request"
  }

  # Handle POST webhooks only
  if request.post?
    return handle_webhook(context)
  end

  @controller.head :bad_request
end