0

Trying to send my log file to my Telegram group when they request it.

File 'log.log' is located in the same directory

@t_a = ENV['TELEGRAM_API_KEY']

def send_log(chatid) 
    file = "log.log" 
    url = "https://api.telegram.org"
    u = "#{url}/bot#{@t_a}"
    conn = Faraday.new(
        url: u
    )

    conn.post('sendDocument', {chat_id: chatid, document: file })
    
end

faraday logs

I, [2022-12-13T16:20:25.153221 #6333] INFO -- : 400 //status

I, [2022-12-13T16:20:25.153473 #6333] INFO -- : //headers

{"server"=>"nginx/1.18.0", "date"=>"Tue, 13 Dec 2022 09:20:25 GMT", "content-type"=>"application/json", "content-length"=>"99", "connection"=>"keep-alive", "strict-transport-security"=>"max-age=31536000; includeSubDomains; preload", "access-control-allow-origin"=>"*", "access-control-expose-headers"=>"Content-Length,Content-Type,Date,Server,Connection"}

I, [2022-12-13T16:20:25.153624 #6333] INFO -- : //body

{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}

This is another suggested way, send an open file object.

def send_log(chatid) 
        file = File.open("log.log") 
        url = "https://api.telegram.org"
        u = "#{url}/bot#{@t_a}"
        conn = Faraday.new(
            url: u
        )
        conn.post('sendDocument', {chat_id: chatid, document: file })       
    end

I, [2022-12-13T16:25:55.845168 #6625] INFO -- :

{"ok":false,"error_code":400,"description":"Bad Request: wrong remote file identifier specified: Wrong character in the string"}

seamus
  • 2,681
  • 7
  • 26
  • 49
  • file:///Users/*user/Desktop/telegram-binance-bot/log.txt, i have tried this file path as well – seamus Dec 13 '22 at 10:24

0 Answers0