If you have a trouble or a bug — please, write about it in this forum
User avatar
dzaugg
Hi!
I followed all instructions in https://nsoft-s.com/mychatarticles/1175 ... egram.html.
I created a bot on telegram.
I made my MyChat server available on the internet.$
I installed certificates for ssl encryption.
I entered my bot token in MyChat and it says : " Telegram bot is connected"

Then I entered the /start command in the bot and nothing happens.
I tried all combinations of the "auto-registration" and "auto-activation" buttons but it didnt change anything.
Please help,
User avatar
Alona Kutsenko
Hello! We will check it on Monday. Stay tuned!
User avatar
dzaugg
Hi!
I found a partial solution to my problem.
It was related to my network and firewall settings and not to mychat.
Now when someone sends me a message and I'm offline, I receive it through telegram.

But when I answer the user doesn't receive my reply...
User avatar
Alona Kutsenko
How do you reply?
You need to long-tap on the message in Telegram, choose "Reply", and then type your message.
User avatar
dzaugg
Yes, that's what I did
User avatar
Alona Kutsenko
Ok, we will test it and post the answer later in this thread.
User avatar
Alona Kutsenko
1. Can you provide your full server version (e.g 8.3.3)?
2. Post a log from your server, the section "Tools" -> "Integration" -> "Telegram bot"->"Connection logs" (copy the text).
3. Did you enable the script in the section "Tools" -> "Scripts" -> "Event scripts" -> "OnRequestByRest" -> "Telegram". If not, tick the box.
User avatar
dzaugg
1) Server 8.3.3
2) Here's the log. I replaced my server addresses and FQDN with placeholders for privacy puposes. If you need them I can send them in a private msg.

Webhook info:
Code: Select all
{"ok":true,"result": "id":1661486918,"is_bot":true,"first_name":"REE_MyChat","username":"MyChatSrv_bot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":false}}

Check on Telegram:
Code: Select all
{"ok":true,"result": "url":"https://[...]:8443/rest/Telegram/1661486918:AAGXa55c1Ok0aN2Xhkxslg2FWi1RzCmhnmk/","has_custom_certificate":false,"pending_update_count":1,"last_error_date":1612187053,"last_error_message":"Read timeout expired","max_connections":40,"ip_address":"[...]"}}


3) Yes I did
User avatar
Alona Kutsenko
Please, show the content of your Telegram script: "Tools" -> "Scripts" -> "Event scripts" -> "OnRequestByRest" -> "Telegram".

Also, show the Node log : "Tools" -> "Logs" -> "Logs type" -> "NodeJS logs". It must match with the request time on https://[...]:8443/rest/Telegram/...
User avatar
dzaugg
Here's the Telegram script:

Code: Select all
***

// -----------------------------------------------------------------------------------
// ver 1.0 / Jun 9, 2017, (c) Alexey Pikurov, [email protected]
// -----------------------------------------------------------------------------------

function OnRequestByREST(sBody, sParams, sHeaders, sURL, sIPv4, sIPv6: string; iType: integer): string;
var
  sFirstName, sLastName, sNickName, sTelegramID, sText: string;
begin
  sFirstName  := '';
  sLastName   := '';
  sNickName   := '';
  sTelegramID := '';
  sText       := '';
 
  JSONGetString(sBody, 'message.from.id', sTelegramID);
  JSONGetString(sBody, 'message.from.first_name', sFirstName);
  JSONGetString(sBody, 'message.from.last_name', sLastName);
  JSONGetString(sBody, 'message.from.username', sNickName);
  JSONGetString(sBody, 'message.text', sText);
 
    if LowerCase(sText) = '/start' then
      mIntegrationTelegramAddUser(sTelegramID, sFirstName, sLastName, sNickName);
end;

begin

end.

***
User avatar
Alona Kutsenko
Today, we are releasing MyChat 8.4. Please update and replace your old script with this one! :)

Here is the latest version of the script — 2.1.
Code: Select all
// -----------------------------------------------------------------------------------
// ver 2.1 / Feb 1, 2021, (c) Alexey Pikurov, [email protected]
// -----------------------------------------------------------------------------------

function OnRequestByREST(sBody, sParams, sHeaders, sURL, sIPv4, sIPv6: string; iType: integer): string;
var
  sFirstName, sLastName, sNickName, sTelegramID, sText, sData: string;
  iResult, x, iUIN, iUINFrom: integer;
begin
  sFirstName  := '';
  sLastName   := '';
  sNickName   := '';
  sTelegramID := '';
  sText       := '';
 
  // get request data
  JSONGetString(sBody, 'message.from.id', sTelegramID);
  JSONGetString(sBody, 'message.from.first_name', sFirstName);
  JSONGetString(sBody, 'message.from.last_name', sLastName);
  JSONGetString(sBody, 'message.from.username', sNickName);
  JSONGetString(sBody, 'message.text', sText);

    // if user is connecting to the Telegram bot for the first time
    if LowerCase(sText) = '/start' then mIntegrationTelegramAddUser(sTelegramID, sFirstName, sLastName, sNickName)
      else begin // maybe user send reply message to the bot
        iResult := JSONGetString(sBody, 'message.reply_to_message.entities[0].url', sData);
       
          if iResult = 0 then begin
            // get receiver's UIN
            x := pos('?uin=', sData) + 5;
            iUIN := StrToIntDef(copy(sData, x, pos('&', sData) - x), -1);

            // get sender's UIN by user Telegram ID
            iUINFrom := mIntegrationTelegramGetMyChatUINByTelegramID(sTelegramID);

              // if sender and receiver are exists
              if (iUIN <> -1) and (iUINFrom > 0) then begin
                if Length(sText) > 0 then begin
                  // multi-line text
                  sData := '[Telegram] ' + ReplaceString(sText, #10, CRLF, true, false);
                  // send private message into MyChat
                  mSendPrivateMessage(iUINFrom, iUIN, sData, 1);
                end else begin
             JSONSetInteger(sBody, 'UINFrom', iUINFrom);
                  JSONSetInteger(sBody, 'UINTo',   iUIN);
                  mNodeCommand('GetTelegramAttach', sBody);
                end
              end; 
          end;
     
      end;
     
  result := '{}';
end;

begin

end.
User avatar
dzaugg
How do I upgrade to 8.4 on my production server?
Can I simply install over the previous version after stopping the service?

I tried the script on my 8.3.3 server
I get [Error] (42:64): Invalid number of parameters on line 42
mSendPrivateMessage(iUINFrom, iUIN, sData, 1);

Does the new scipt only work on the new server?
User avatar
Alona Kutsenko
We haven't released the new version yet. But it's going to be today. You will be notified as soon as the new version is released.
The update instruction is on the Help page.
User avatar
dzaugg
And about the script error? Do I have to wait for the new release?
User avatar
dzaugg
New script + new version did the trick: it works!

One more question: what do the checkboxes "Auto registration of MyChat users" and "Auto activation" do exactly ?
User avatar
Alona Kutsenko
1. Auto-registration is when a user press "Start" for the Telegram bot, and he is automatically added to the server with the same nickname he has in Telegram.

2. Auto-activation is for allowing a user to work with Telegram bot: receive messages from MyChat when he is offline and reply to them in Telegram.