E
E
Eugene2021-09-20 21:25:40
Delphi
Eugene, 2021-09-20 21:25:40

Can Telegram be used in conjunction with a Windows application?

Hello.
I design electronic devices for different applications. As a rule, they transmit data from sensors either to a personal computer under Windows or to a specialized application on the phone via Bluetooth. I would like to finalize the application on the computer, so that it also sends this data to the cart, if the Internet is available.
If I understand correctly, do I need to dig towards the telegram bot api? For the user to add this bot to himself.
But it's a little unclear to me if the bot is one, for all users. And there are dozens of users. How will the data come to those users who need it? I need an application on my computer to send data to a specific person. Or should I look at some other messenger? What do you advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2021-09-20
@Zugusik

To do this, it is enough to write one line.

TDownload.GetRequest('https://api.telegram.org/' + TG_BOT_TOKEN + '/sendMessage?chat_id=' + ChatId + '&text=' + TURLEncoding.URL.Encode(Text));

Where TDownload.GetRequest simply performs a simple GET request without reading the response, and TG_BOT_TOKEN is the bot token string that will be issued when creating a bot in Telegram
Bot token example "bot1234567899:GFGJDGSDJFHGJSD_sdFdfskjdfhskdf
"
uses System.Net.HTTPClient;
function GetRequest(URL: string): Boolean;
var
  HTTP: THTTPClient;
begin
  Result := False;
  if URL.IsEmpty then
    Exit;
  HTTP := THTTPClient.Create;
  HTTP.HandleRedirects := True;
  try
    try
      Result := HTTP.Get(URL).StatusCode = 200;
    finally
      HTTP.Free;
    end;
  except
    Result := False;
  end;
end;

TURLEncoding is located here System.NetEncoding.
The most difficult thing will probably be to get the ChatId of the chat in which you will need to write. If to yourself, then this is the user's Id. Those. you just need to make a list of ChatIds (Ids of the users you want) and run a query with each ChatId.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question