K
K
kr_ilya2019-07-15 12:09:29
Node.js
kr_ilya, 2019-07-15 12:09:29

How to upload a file using telegram api?

Something I don’t understand at all ... Why is everything so complicated with this telegram api and there are no sensible examples on the node .. But there are a lot of bots ...
In short, you need to send a file to my bot using api, I found a library for the node .
I tried to run the code below code, but immediately ran into a misunderstanding. If during authorization you need to send the code received via SMS, then the script needs to be run 2 times every time (1. Get the code 2. Write the code to the script and log in.)
I understand that the library will work fine with the frontend, but what if there is no frontend and can't it be?
Isn't it possible to just log in once and hold on to the session?!
Secondly, is it necessary to use this authorization if I need to send a file on my behalf to the bot, can't it be done just by having a secret key?
What should I do next? How to come from this to sending a file and not bother with authorizations? Can you give examples of how this is generally implemented? The script will be run on the crown, so I should not receive any keys, just send the file.
Explain.

import MTProto from 'telegram-mtproto'

const phone = {
  num : '+9996620001',
  code: '22222'
}

const api = {
  layer          : 57,
  initConnection : 0x69796de9,
  api_id         : 49631
}

const server = {
  dev: true //We will connect to the test server.
}           //Any empty configurations fields can just not be specified

const client = MTProto({ server, api })

async function connect(){
  const { phone_code_hash } = await client('auth.sendCode', {
    phone_number  : phone.num,
    current_number: false,
    api_id        : 49631,
    api_hash      : 'fb050b8f6771e15bfda5df2409931569'
  })
  const { user } = await client('auth.signIn', {
    phone_number   : phone.num,
    phone_code_hash: phone_code_hash,
    phone_code     : phone.code
  })

  console.log('signed as ', user)
}

connect()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question