Module: Dialog::BotApi

Defined in:
lib/telegram/botapi.rb,
lib/telegram/infra_info.rb

Class Method Summary collapse

Class Method Details

.apiAction(args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/telegram/botapi.rb', line 29

def apiAction(args)  
  args[:perf][:preApiAction] = Time.now        
  op = args[:api][:op]
  Dialog.logger.debug "Operation #{op}: #{args[:smsg]}\n"
  a = args[:bot].api.send("#{op}".to_sym, args[:smsg])   
  Dialog.logger.debug "API Answer - #{a}"                      
  
  args[:perf][:postApiAction] = Time.now                
  if a["ok"] == true
    return a
  else
    Dialog.logger.info "ERROR in bot.api interaction #{"#{op}".to_sym}, msg: #{args[:smsg]}"        
  end
  args[:smsg] = {}
  args[:api] = {}
  args[:x] = {}
end

.apiActionGet(args) ⇒ Object



17
18
19
20
21
# File 'lib/telegram/botapi.rb', line 17

def apiActionGet(args)   
  args[:api][:op] = "get#{args[:api][:op]}"
  a = apiAction(args)
  return a
end

.apiActionSend(args) ⇒ Object



23
24
25
26
27
# File 'lib/telegram/botapi.rb', line 23

def apiActionSend(args)
  args[:api][:op] = "send#{args[:api][:op]}"
  a = apiAction(args)
  return a
end

.runMetacommand__info(args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/telegram/infra_info.rb', line 17

def runMetacommand__info(args) 
  
  if args[:mmsg][:reply] == nil
    args[:smsg][:text] =  "О чём именно вам дать информацию?\n Отметьте объект с помощью 'Reply' и отправьте ему сообщение '_info' или '_инфо'\n"
    Bot::BotApi.new.apiActionSend(args) 
  else          
    text = "Информация об объекте:\n\n"
    text = text + "Как-то раз (а именно, <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:date].to_s,'%s')}</b>) \n"
    text = text + "пользователь <b>#{args[:mmsg][:reply][:mmsg][:username]}</b> с ID <b>#{args[:mmsg][:reply][:mmsg][:user_id]}</b> \n"        
    text = text + "отправил сообщение с ID \"<b>#{args[:mmsg][:reply][:mmsg][:message_id]}</b>\"\n"
    text = text + "в чат контекста \"<b>#{args[:mmsg][:reply][:mmsg][:chat_context]}</b>\" под названием \"<b>#{args[:mmsg][:reply][:mmsg][:chat_title]}</b>\" с ID \"<b>#{args[:mmsg][:reply][:mmsg][:chat_id]}</b>\"\n"  
    text = text + "(на самом деле, это был forward сообщения пользователя <b>#{args[:mmsg][:reply][:mmsg][:forward][:from][:username]}</b> с ID <b>#{args[:mmsg][:reply][:mmsg][:forward][:from][:user_id]}</b>  от <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:forward][:date].to_s,'%s')}</b>\n"   if ! args[:mmsg][:reply][:mmsg][:forward].nil?        
    text = text + "Сообщение было отредактировано  <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:edit][:date].to_s,'%s')}</b>\n"   if ! args[:mmsg][:reply][:mmsg][:edit].nil?
    text = text + "\nДополнительная информация:\n"        
    text = text + "Order(Порядок): \"<b>#{args[:mmsg][:reply][:mmsg][:_order]}</b>\"\n"
    text = text + "Family(Семейство): \"<b>#{args[:mmsg][:reply][:mmsg][:_family]}</b>\"\n"

    if args[:mmsg][:reply][:mmsg][:_order] ==  Bot::Naming::Class::Message::Order.Media
      text = text + "ID файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_id]}</b>\"\n"
      text = text + "Название файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_name]}</b>\"\n"  if ! args[:mmsg][:reply][:mmsg][:media][:file_name].nil?                
      text = text + "MIME-тип: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:mime_type]}</b>\"\n" if ! args[:mmsg][:reply][:mmsg][:media][:mime_type].nil?
      text = text + "Размер файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_size]} байта</b>\"\n"
      text = text + "Описание к #{args[:mmsg][:reply][:mmsg][:_family]} : \"<b>#{args[:mmsg][:reply][:mmsg][:media][:caption]}</b>\n" if ! args[:mmsg][:reply][:mmsg][:media][:caption] == nil
    end    
    args[:smsg][:text] = text
  end
  
end

.socks5_connectionObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/telegram/botapi.rb', line 48

def socks5_connection
  require 'telegram/bot/adapters/socks5'

  host = "https://#{Dialog.config.proxy.host}:#{Dialog.config.proxy.port}"                                            
  proxy_opts = {
      uri: URI.parse(host),
      user: Dialog.config.proxy.,
      password: Dialog.config.proxy.pass,
      socks: true
  }

    c = Faraday.new(url: Dialog.config.host.apiUri,
                            ssl: {verify:false},
                            request: { proxy: proxy_opts }) do |c|
      c.request :multipart
      c.request :url_encoded
      Faraday::Adapter.register_middleware socks5: Telegram::Bot::Adapters::Socks5
      c.adapter :socks5  
    end
    return c        
end