Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask user for user id instead of chat id (aka simpler Telegram setup) #110

Open
Dretech opened this issue Sep 18, 2018 · 50 comments
Open

Ask user for user id instead of chat id (aka simpler Telegram setup) #110

Dretech opened this issue Sep 18, 2018 · 50 comments

Comments

@Dretech
Copy link
Contributor

Dretech commented Sep 18, 2018

I'm pleasantly surprised that the Telegram 2fa is integrated in the easily installable apps for Nextcloud 14. Unfortunately I was not able to enable the Telegram 2fa after following the instructions from the app and the 2fa gateway website.
In the security settings of my user I tried to enter my Telegram ID, but the app responds with the following error message:
afbeelding
(In the input field I filled in my Telegram ID, but I don't want to show this ID on a public website)

What is going wrong?

Thanks in advance for your reply.

André

@ChristophWurst
Copy link
Member

Hey, @Dretech :)

So, you've set up a new bot, started a conversation from your Telegram user and checked the ID with the "ID Bot", correct? Is that the ID you entered?

Is there anything in your data/nextcloud.log?

@Dretech
Copy link
Contributor Author

Dretech commented Sep 18, 2018

Hi Christoph,

Thank you for your quick reply.

So, you've set up a new bot, started a conversation from your Telegram user and checked the ID with the "ID Bot", correct? Is that the ID you entered?

Yes, I did

The last line of my nextcloud.log file is:
{"reqId":"1EwDcbHK7ZqakRFYR4kc","level":3,"time":"2018-09-18T18:08:11+00:00","remoteAddr":"192.168.2.1","user":"andre","app":"PHP","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/usr\/share\/webapps\/nextcloud\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

The latest version of php-intl is installed. So what is causing this error?

@ChristophWurst
Copy link
Member

The latest version of php-intl is installed. So what is causing this error?

This doesn't read like it would cause any problems here.

@Dretech
Copy link
Contributor Author

Dretech commented Sep 25, 2018

Thank you for your reply.

Can you describe which records in the database are made (and what contents they must have) after Telegram 2fa is activated? (The Telegram 2fa app has changed since I made the first version).

@ChristophWurst
Copy link
Member

@Dretech
Copy link
Contributor Author

Dretech commented Sep 26, 2018

I followed the instructions in the admin docs. I can't find anything in the admin docs about which database records will be created after enabling 2fa with Telegram for u user.

@ChristophWurst
Copy link
Member

You don't (and shouldn't) change any database values manually, the interactive commands will do that for you. That's what they are for 😉

Once that's done, go to your personal settings in the Nextcloud UI and you'll find the gateway user settings in the security section.

@Dretech
Copy link
Contributor Author

Dretech commented Sep 27, 2018

After running occ twofactorauth:gateway:configure telegram I entered my Telegram Bot token and I got the message `Using -my Telegram bot token-

After that I tried to fill in my Telegram ID in the personal - security settings of the web interface of Nextcloud. After entering my Telegram id I got the next error message (see enclosed printscreen). (Before making the printscreen I changed my Telegram ID to 999999999, but the error message is concerning my real Telegram ID).

printscreen
`

@ChristophWurst
Copy link
Member

Did you receive a code after entering your telegram ID?

How did you update to the latest version of this app? Are there any entries in your nextcloud.log when that error occurs?

@Dretech
Copy link
Contributor Author

Dretech commented Sep 28, 2018

No, I did not receive a code after entering my Telegram (user) ID.

I installed the app from the apps menu (in the right top of Nextcldoud) see printscreen below.
afbeelding . My current version of Nextcloud is: 14.0.0

Below you will find today's records of nextcloud.log containing 'Telegram':

{"reqId":"mOsBT7MIOzjPmKkqCDXJ","level":3,"time":"2018-09-28T18:24:38+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"PHP","method":"GET","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/usr\/share\/webapps\/nextcloud\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

{"reqId":"9Cv5wGU3gFbBr6ZtG4mF","level":3,"time":"2018-09-28T18:25:49+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"PHP","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"Trying to get property 'message' of non-object at \/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php#92","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

{"reqId":"9Cv5wGU3gFbBr6ZtG4mF","level":3,"time":"2018-09-28T18:25:49+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"PHP","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"Trying to get property 'chat' of non-object at \/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php#92","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

{"reqId":"9Cv5wGU3gFbBr6ZtG4mF","level":3,"time":"2018-09-
28T18:25:49+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"PHP","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"Trying to get property 'id' of non-object at \/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php#92","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

{"reqId":"9Cv5wGU3gFbBr6ZtG4mF","level":3,"time":"2018-09-28T18:25:49+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"index","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":{"Exception":"UnexpectedValueException","Message":"Only integers, floats and strings are allowed as value","Code":0,"Trace":[{"file":"\/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":93,"function":"setUserValue","class":"OC\\AllConfig","type":"->","args":["andre","twofactor_gateway","chat_id",null]},{"file":"\/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":67,"function":"getChatId","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},{"__class__":"Telegram\\Bot\\Api"},277245919]},{"file":"\/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/SetupService.php","line":92,"function":"send","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},"277245919","004324 is your Nextcloud verification code."]},{"file":"\/usr\/share\/webapps\/nextcloud\/apps\/twofactor_gateway\/lib\/Controller\/SettingsController.php","line":90,"function":"startSetup","class":"OCA\\TwoFactorGateway\\Service\\SetupService","type":"->","args":[{"__class__":"OC\\User\\User"},"telegram","277245919"]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":166,"function":"startVerification","class":"OCA\\TwoFactorGateway\\Controller\\SettingsController","type":"->","args":["telegram","277245919"]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":99,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/AppFramework\/App.php","line":118,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\TwoFactorGateway\\Controller\\SettingsController","startVerification",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/Route\/Router.php","line":297,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/usr\/share\/webapps\/nextcloud\/lib\/base.php","line":989,"function":"match","class":"OC\\Route\\Router","type":"->","args":["\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start"]},{"file":"\/usr\/share\/webapps\/nextcloud\/index.php","line":42,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"\/usr\/share\/webapps\/nextcloud\/lib\/private\/AllConfig.php","Line":214,"CustomMessage":"--"},"userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

{"reqId":"9Cv5wGU3gFbBr6ZtG4mF","level":3,"time":"2018-09-28T18:25:49+00:00","remoteAddr":"192.168.2.203","user":"andre","app":"PHP","method":"POST","url":"\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"You are using a fallback implementation of the intl extension. Installing the native one is highly recommended instead. at \/usr\/share\/webapps\/nextcloud\/3rdparty\/patchwork\/utf8\/src\/Patchwork\/Utf8\/Bootup\/intl.php#18","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.0.19"}

@MartinGE47
Copy link

I have the same problem. Some one can help us

@ChristophWurst
Copy link
Member

Trying to get property 'message' of non-object at /usr/share/webapps/nextcloud/apps/twofactor_gateway/lib/Service/Gateway/Telegram/Gateway.php#92

So somewhere around

$updates = $api->getUpdates();
/** @var Update $update */
$update = current(array_filter($updates, function (Update $data) use ($userId) {
if ($data->message->text === "/start" && $data->message->from->id === $userId) {
return true;
}
return false;
}));
// TODO: handle missing `/start` message and `$update` null values
$chatId = $update->message->chat->id;
$this->config->setUserValue($user->getUID(), 'twofactor_gateway', 'telegram_chat_id', $chatId);
return (int)$chatId;
.

Could you manually check the updates on your bot to see if they contain the event of a new conversation with your user?

@Dretech
Copy link
Contributor Author

Dretech commented Oct 1, 2018

It seems Nextcloud does not connect to Telegram. After trying to enable Telegram 2fa in Nextcloud the status of the Telegram Api is:

afbeelding
After sending a message to the Nextcloud 2fa bot I created in the Telegram app the status of the Telegram APi is:
afbeelding

The full conents of the json repsonse is:

{"ok":true,"result":[{"update_id":562736860,
"message":{"message_id":3,"from":{"id":999999999,"is_bot":false,"first_name":"Andr\u00e9","last_name":"from Holland","language_code":"nl"},"chat":{"id":99999999,"first_name":"Andr\u00e9","last_name":"Fondse","type":"private"},"date":1538418166,"text":"Test"}}]}

Tonight I also tested the first version of the Telegram 2fa code I created and that is still working.

@ChristophWurst
Copy link
Member

After sending a message to the Nextcloud 2fa bot I created in the Telegram app the status of the Telegram APi is:

You have to first contact the bot before you will be able to send messages as a bot. That is how you can use bots to send authentication code. The bot is not allowed to initiate the conversation.

Does it work now? Can you enter the ID you got from the id bot and receive a confirmation message?

@Dretech
Copy link
Contributor Author

Dretech commented Oct 2, 2018

No, it does not work now. I don't get a conformation message after sending my Telegram ID. I forgot to write that in the message yesterday.

@ChristophWurst
Copy link
Member

I will try to add more debug logging to the Telegram code to help debug these scenarios.

@Dretech
Copy link
Contributor Author

Dretech commented Oct 2, 2018

Thanks

@mmartinortiz
Copy link

I'm having a similar issue. I use the same bot in other applications for getting notifications from my server, so I guess it is up and working properly (we do not need to create any special command on the bot, right?).

After introducing the Chat ID obtained with the get_id bot, I see the following exception in the nextcloud.log (extract)

"message": {"Exception":"UnexpectedValueException","Message":"Only integers, floats and strings are allowed as value","Code":0," ... }

The value I've introduced is compose by 8 positive integers. I've also tried with the "User Name" provided by the get_id bot

@ChristophWurst
Copy link
Member

@mmartinortiz please see #126, test the provided package and report back the debug log entries. Thanks.

@mmartinortiz
Copy link

mmartinortiz commented Oct 6, 2018

Hi @ChristophWurst,

After installing the provided package, this is the last line of nextcloud.log (I did not find other debug data). The Telegram API does not show activity. I've replaced sensitive data.

{
  "reqId": "Jg20asmA0bX4a6kiIFQZ",
  "level": 3,
  "time": "2018-10-07T09:12:17+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "m",
  "app": "index",
  "method": "POST",
  "url": "\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start",
  "message": {
    "Exception": "UnexpectedValueException",
    "Message": "Only integers, floats and strings are allowed as value",
    "Code": 0,
    "Trace": [
      {
        "file": "\/config\/www\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php",
        "line": 107,
        "function": "setUserValue",
        "class": "OC\\AllConfig",
        "type": "->",
        "args": [
          "m",
          "twofactor_gateway",
          "telegram_chat_id",
          null
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php",
        "line": 75,
        "function": "getChatId",
        "class": "OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway",
        "type": "->",
        "args": [
          {
            "__class__": "OC\\User\\User"
          },
          {
            "__class__": "Telegram\\Bot\\Api"
          },
          99999999
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/apps\/twofactor_gateway\/lib\/Service\/SetupService.php",
        "line": 92,
        "function": "send",
        "class": "OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway",
        "type": "->",
        "args": [
          {
            "__class__": "OC\\User\\User"
          },
          "99999999",
          "666666 is your Nextcloud verification code."
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/apps\/twofactor_gateway\/lib\/Controller\/SettingsController.php",
        "line": 90,
        "function": "startSetup",
        "class": "OCA\\TwoFactorGateway\\Service\\SetupService",
        "type": "->",
        "args": [
          {
            "__class__": "OC\\User\\User"
          },
          "telegram",
          "99999999"
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php",
        "line": 166,
        "function": "startVerification",
        "class": "OCA\\TwoFactorGateway\\Controller\\SettingsController",
        "type": "->",
        "args": [
          "telegram",
          "99999999"
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php",
        "line": 99,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\TwoFactorGateway\\Controller\\SettingsController"
          },
          "startVerification"
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/private\/AppFramework\/App.php",
        "line": 118,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\TwoFactorGateway\\Controller\\SettingsController"
          },
          "startVerification"
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php",
        "line": 47,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\TwoFactorGateway\\Controller\\SettingsController",
          "startVerification",
          {
            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
          },
          {
            "gateway": "telegram",
            "_route": "twofactor_gateway.settings.startVerification"
          }
        ]
      },
      {
        "function": "__invoke",
        "class": "OC\\AppFramework\\Routing\\RouteActionHandler",
        "type": "->",
        "args": [
          {
            "gateway": "telegram",
            "_route": "twofactor_gateway.settings.startVerification"
          }
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/private\/Route\/Router.php",
        "line": 297,
        "function": "call_user_func",
        "args": [
          {
            "__class__": "OC\\AppFramework\\Routing\\RouteActionHandler"
          },
          {
            "gateway": "telegram",
            "_route": "twofactor_gateway.settings.startVerification"
          }
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/lib\/base.php",
        "line": 987,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start"
        ]
      },
      {
        "file": "\/config\/www\/nextcloud\/index.php",
        "line": 42,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": [
          
        ]
      }
    ],
    "File": "\/config\/www\/nextcloud\/lib\/private\/AllConfig.php",
    "Line": 214,
    "CustomMessage": "--"
  },
  "userAgent": "Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0",
  "version": "14.0.2.0"
}

@ChristophWurst
Copy link
Member

Did you actually set the log level to 0/debug?

@mmartinortiz
Copy link

mmartinortiz commented Oct 7, 2018

{
  "reqId": "Jg20asmA0bX4a6kiIFQZ",
  "level": 0,
  "time": "2018-10-07T09:12:17+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "m",
  "app": "core",
  "method": "POST",
  "url": "\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start",
  "message": "Scss is disabled for \/config\/www\/nextcloud\/core\/css\/jquery-ui-fixes.scss, ignoring",
  "userAgent": "Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0",
  "version": "14.0.2.0"
}
{
  "reqId": "Jg20asmA0bX4a6kiIFQZ",
  "level": 0,
  "time": "2018-10-07T09:12:17+00:00",
  "remoteAddr": "172.18.0.1",
  "user": "m",
  "app": "core",
  "method": "POST",
  "url": "\/index.php\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start",
  "message": "Scss is disabled for \/config\/www\/nextcloud\/core\/css\/server.scss, ignoring",
  "userAgent": "Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko\/20100101 Firefox\/62.0",
  "version": "14.0.2.0"
}

The rest of the entries related to "Scss is disabled for...". I've also updated the log for my previous comment.

@ChristophWurst
Copy link
Member

Again, please enable debug logging. The entry you provided just shows where the error happened, although there must be more log entries fore that. For reference, see https://github.com/nextcloud/twofactor_gateway/pull/126/files. There are numerous logging statements before $this->config->setUserValue is actually invoked.

Please see https://docs.nextcloud.com/server/14/admin_manual/configuration_server/logging_configuration.html and report back when you've got the debug logs.

@ChristophWurst
Copy link
Member

Maybe I'm stating the obvious, but you have to reproduce the error in order to get the debug statements. Changing the log level post mortem won't magically recover them.

@mmartinortiz
Copy link

For the sake of clarity, I'll list the steps I've followed for the logs provided:

  • Disable and remove twofactor_gateway from my Nextcloud server
  • Copy the earlier mentioned twofactor_gateway package manually to the apps folder
  • Enable the twofactor_gateway application
  • Set loglevel => 0 on config.php
  • Configure the twofactor_gateway application with my bot token from the command line
  • From my user settings->security, enable the Telegram gateway and introduce my Chat Id.
  • Copy the relevant lines from the nextcloud.log file

Since my server is used by several users, I see now that the debug lines got quickly lost.

In any case, here are the debug messages (directly from the web interface log)//:

Debug | no app in context | got 0 updates | 2018-10-07T18:32:32+0200
Debug | no app in context | trying to get chat id from updates | 2018-10-07T18:32:32+0200
Debug | no app in context | telegram bot token: <bot token> | 2018-10-07T18:32:32+0200
Debug | no app in context | sending telegram message to <chat id>, message: <auth code> is your Nextcloud verification code. | 2018-10-07T18:32:32+0200

I've used the logged <bot token> for accessing manually to the URL https://api.telegram.org/bot<bot_token>/getupdates for checking that it is correct.

@ChristophWurst
Copy link
Member

Okay. So there are no updates available for the server. Did you (re)start the conversation with the bot as instructed on the provider settings page? The app can't map telegram users to Nextcloud users if they haven't started a chat recently.

@ChristophWurst
Copy link
Member

Please elaborate how these other systems are set up. What do you enter so that the system knows which Telegram user/chat to send messages to?

I'm not a Telegram pro, in fact I haven only really used shortly to implement this feature. But from what I've researched on the topic there is no way for a bot to start the conversation with a user, so the user has to start it first. This first message will trigger an event which can be read by the telegram API. We use this event to map Nextcloud users to Telegram chats.

@mmartinortiz
Copy link

In few words, the mechanism to get the bot up and running is what you described:

  1. Create a bot with the Bot Father, save somewhere the Bot Token
  2. Start a conversation with your brand new bot
  3. Get your Chat id using the Get_id bot

From there, you can configure any program to make use of the Telegram API. The Bot Token and the Chat Id are the two things you need for receiving messages from your bot.

In my case, and previously to the Nextcloud 2FA, I configured my bot to be used by my server, that sends me messages about system updates, users, etc. I also configured the bot, with the same Bot Token and Chat Id in other docker containers for getting messages from the services they were running.

From the debug logs of the gateway, I see that the message is requested to be sent, but it never reach the Telegram API. Could it be that the API used by the gateway is not sending the message for some reason? can we increase the debug level of the API without introducing additional traces to see what is happening? (It has been decades since I programmed in PHP and things have changed a lot, I'm sorry if my questions are too evident)

@ChristophWurst
Copy link
Member

Please keep in mind that with this Nextcloud app, the admin knows and configures the bot, while users just have access to their Telegram account/ID. All they know is the bot ID.

From the debug logs of the gateway, I see that the message is requested to be sent, but it never reach the Telegram API.

What section of the code/process are you talking about? If the app fails to read the chat ID it obviously never sends out any Telegram message.

@mmartinortiz
Copy link

Please keep in mind that with this Nextcloud app, the admin knows and configures the bot, while users just have access to their Telegram account/ID. All they know is the bot ID

That is something I wanted to ask. Since each user may have its own bot for authentification. Should not be the configuration (bot token and chat id) be done in the user's setting space?

What section of the code/process are you talking about? If the app fails to read the chat ID it obviously never sends out any Telegram message.

From the last debug line

Debug | no app in context | sending telegram message to <chat id>, message: <auth code> is your Nextcloud verification code. | 2018-10-07T18:32:32+0200

The chat id was correct, but my bot never received the message. The API is asked to send the message, but from the log we do not know if it really sends it.

@ChristophWurst
Copy link
Member

That is something I wanted to ask. Since each user may have its own bot for authentification. Should not be the configuration (bot token and chat id) be done in the user's setting space?

No. There is one bot for all users.

@ChristophWurst
Copy link
Member

How did you actually obtain the chat ID?

@Dretech
Copy link
Contributor Author

Dretech commented Oct 9, 2018

Should not be the configuration (bot token and chat id) be done in the user's setting space?

In my opinion the bot token is stored in the Nextcloud administrator setting space and the chad id in the user setting space. Because the administrator is the person who can activate the 2fa app.

@mmartinortiz
Copy link

Because the administrator is the person who can activate the 2fa app.

@Dretech, I agree, but the user is the person that decides to use it. A user can have already a specific bot for its personal use. But I understand that the administrator can set a bot as a "default bot"

No. There is one bot for all users.

@ChristophWurst, Can I ask for the technical reasons for that?

How did you actually obtain the chat ID?

Using the get id bot (as stated on the admin docs)

@ChristophWurst
Copy link
Member

Using the get id bot (as stated on the admin docs)

That doesn't make sense to me.

Correct me if I'm wrong, but as far as I understood, every chat has it's own unique id. And so does every user. In order for a bot to send a message, it has to know the chat id of the conversation with the user. What the id bot tells you is your user ID. If it tells you a chat ID, that can only be the conversation with the id bot but now with your 2FA bot.

Now, this app asks you to start a conversation with your 2FA bot. It then asks you to enter your user ID obtained through the id bot. This app will then check for newly started conversations of the provided user ID. If a match is found, it can get the chat ID of the conversation between your user and the 2FA bot.

This is how the current setup logic works. If there were any way for a user to (easily) get the chat ID of the chat with the 2FA bot, we could have them enter that directly and skip the lookup step in the bot updates.

@ChristophWurst
Copy link
Member

No. There is one bot for all users.

@ChristophWurst, Can I ask for the technical reasons for that?

There are no technical reasons/limitations. This app simply integrates Telegram in a way it is easy to set up and use for everyone. We must not assume that anybody can and wants to set up their own bot as that is a very technical procedure.

@ChristophWurst
Copy link
Member

ChristophWurst commented Oct 10, 2018

This is how the current setup logic works.

FYI: this is almost exactly what the official bot docs suggest, except that we don't rely on an initial shared secret: https://core.telegram.org/bots#deep-linking-example

Edit: also see https://stackoverflow.com/questions/31078710/how-to-obtain-telegram-chat-id-for-a-specific-user.

@Dretech
Copy link
Contributor Author

Dretech commented Oct 10, 2018

There are no technical reasons/limitations. This app simply integrates Telegram in a way it is easy to set up and use for everyone. We must not assume that anybody can and wants to set up their own bot as that is a very technical procedure.

I agree with this. Moreover the administrator has to install the 2fa app and in my opinion is setting up the Telegram bot part of the job for the administrator.

@Freekers
Copy link

Freekers commented Oct 15, 2018

I am having the same issue. I'm also using my bot for other projects such as Domoticz or my own Python script, yet I was unable to get it to work with Nextcloud.

I am using the official Nextcloud docker 14.0.3-apache with the extra debugging version of the twofactor_gateway which can be found here: #126

To setup and configure the app, I followed the exact same instructions as this guy, who got it working: https://translate.google.com/translate?sl=auto&tl=en&js=y&prev=_t&hl=nl&ie=UTF-8&u=https%3A%2F%2Fmatoken.org%2Fblog%2F2018%2F09%2F19%2Ftwo-factor-authentication-using-nextgram-14-telegram%2F%23_occ_%25E3%2582%25B3%25E3%2583%259E%25E3%2583%25B3%25E3%2583%2589%25E3%2581%25A7_telegram_bot_%25E3%2581%25AE%25E3%2583%2588%25E3%2583%25BC%25E3%2582%25AF%25E3%2583%25B3%25E8%25A8%25AD%25E5%25AE%259A&edit-text=

The debug logging is big chunk of text, but apart from the 404 regarding the TelegramResponseException not found, there is not much from what I can see that goes wrong:

{"reqId":"zD816Eixo0of5jb4ddj5","level":0,"time":"2018-10-15T17:47:14+00:00","remoteAddr":"12.34.56.78","user":"freek","app":"no app in context","method":"POST","url":"\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"sending telegram message to CHATID_REMOVED_FOR_PRIVACY, message: 202382 is your Nextcloud verification code.","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.3.0"}

{"reqId":"zD816Eixo0of5jb4ddj5","level":0,"time":"2018-10-15T17:47:14+00:00","remoteAddr":"12.34.56.78","user":"freek","app":"no app in context","method":"POST","url":"\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"telegram bot token: BOTID_REMOVED_FOR_PRIVACY","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.3.0"}

{"reqId":"zD816Eixo0of5jb4ddj5","level":0,"time":"2018-10-15T17:47:14+00:00","remoteAddr":"12.34.56.78","user":"freek","app":"no app in context","method":"POST","url":"\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":"trying to get chat id from updates","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.3.0"}

{"reqId":"zD816Eixo0of5jb4ddj5","level":3,"time":"2018-10-15T17:47:14+00:00","remoteAddr":"12.34.56.78","user":"freek","app":"index","method":"POST","url":"\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start","message":{"Exception":"Telegram\\Bot\\Exceptions\\TelegramResponseException","Message":"Not Found","Code":404,"Trace":[{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":100,"function":"create","class":"Telegram\\Bot\\Exceptions\\TelegramResponseException","type":"::","args":[{"__class__":"Telegram\\Bot\\TelegramResponse"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":81,"function":"makeException","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":51,"function":"decodeBody","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramClient.php","line":130,"function":"__construct","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"},{"__class__":"GuzzleHttp\\Psr7\\Response"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramClient.php","line":82,"function":"getResponse","class":"Telegram\\Bot\\TelegramClient","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"},{"__class__":"GuzzleHttp\\Psr7\\Response"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Traits\/Http.php","line":304,"function":"sendRequest","class":"Telegram\\Bot\\TelegramClient","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Traits\/Http.php","line":181,"function":"sendRequest","class":"Telegram\\Bot\\Api","type":"->","args":["GET","getUpdates",[]]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Methods\/Update.php","line":47,"function":"get","class":"Telegram\\Bot\\Api","type":"->","args":["getUpdates",[]]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":94,"function":"getUpdates","class":"Telegram\\Bot\\Api","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":75,"function":"getChatId","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},{"__class__":"Telegram\\Bot\\Api"},CHATID_REMOVED_FOR_PRIVACY]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/SetupService.php","line":92,"function":"send","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},"CHATID_REMOVED_FOR_PRIVACY","202382 is your Nextcloud verification code."]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Controller\/SettingsController.php","line":90,"function":"startSetup","class":"OCA\\TwoFactorGateway\\Service\\SetupService","type":"->","args":[{"__class__":"OC\\User\\User"},"telegram","CHATID_REMOVED_FOR_PRIVACY"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":166,"function":"startVerification","class":"OCA\\TwoFactorGateway\\Controller\\SettingsController","type":"->","args":["telegram","CHATID_REMOVED_FOR_PRIVACY"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":99,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/App.php","line":118,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\TwoFactorGateway\\Controller\\SettingsController","startVerification",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/var\/www\/html\/lib\/private\/Route\/Router.php","line":297,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/var\/www\/html\/lib\/base.php","line":987,"function":"match","class":"OC\\Route\\Router","type":"->","args":["\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start"]},{"file":"\/var\/www\/html\/index.php","line":42,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Exceptions\/TelegramResponseException.php","Line":67,"Previous":{"Exception":"Telegram\\Bot\\Exceptions\\TelegramOtherException","Message":"Not Found","Code":404,"Trace":[{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":100,"function":"create","class":"Telegram\\Bot\\Exceptions\\TelegramResponseException","type":"::","args":[{"__class__":"Telegram\\Bot\\TelegramResponse"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":81,"function":"makeException","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramResponse.php","line":51,"function":"decodeBody","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramClient.php","line":130,"function":"__construct","class":"Telegram\\Bot\\TelegramResponse","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"},{"__class__":"GuzzleHttp\\Psr7\\Response"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/TelegramClient.php","line":82,"function":"getResponse","class":"Telegram\\Bot\\TelegramClient","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"},{"__class__":"GuzzleHttp\\Psr7\\Response"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Traits\/Http.php","line":304,"function":"sendRequest","class":"Telegram\\Bot\\TelegramClient","type":"->","args":[{"__class__":"Telegram\\Bot\\TelegramRequest"}]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Traits\/Http.php","line":181,"function":"sendRequest","class":"Telegram\\Bot\\Api","type":"->","args":["GET","getUpdates",[]]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Methods\/Update.php","line":47,"function":"get","class":"Telegram\\Bot\\Api","type":"->","args":["getUpdates",[]]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":94,"function":"getUpdates","class":"Telegram\\Bot\\Api","type":"->","args":[]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/Gateway\/Telegram\/Gateway.php","line":75,"function":"getChatId","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},{"__class__":"Telegram\\Bot\\Api"},CHATID_REMOVED_FOR_PRIVACY]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Service\/SetupService.php","line":92,"function":"send","class":"OCA\\TwoFactorGateway\\Service\\Gateway\\Telegram\\Gateway","type":"->","args":[{"__class__":"OC\\User\\User"},"CHATID_REMOVED_FOR_PRIVACY","202382 is your Nextcloud verification code."]},{"file":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/lib\/Controller\/SettingsController.php","line":90,"function":"startSetup","class":"OCA\\TwoFactorGateway\\Service\\SetupService","type":"->","args":[{"__class__":"OC\\User\\User"},"telegram","CHATID_REMOVED_FOR_PRIVACY"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":166,"function":"startVerification","class":"OCA\\TwoFactorGateway\\Controller\\SettingsController","type":"->","args":["telegram","CHATID_REMOVED_FOR_PRIVACY"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":99,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/App.php","line":118,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\TwoFactorGateway\\Controller\\SettingsController"},"startVerification"]},{"file":"\/var\/www\/html\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\TwoFactorGateway\\Controller\\SettingsController","startVerification",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/var\/www\/html\/lib\/private\/Route\/Router.php","line":297,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"gateway":"telegram","_route":"twofactor_gateway.settings.startVerification"}]},{"file":"\/var\/www\/html\/lib\/base.php","line":987,"function":"match","class":"OC\\Route\\Router","type":"->","args":["\/apps\/twofactor_gateway\/settings\/telegram\/verification\/start"]},{"file":"\/var\/www\/html\/index.php","line":42,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"\/var\/www\/html\/custom_apps\/twofactor_gateway\/vendor\/irazasyed\/telegram-bot-sdk\/src\/Exceptions\/TelegramResponseException.php","Line":67},"CustomMessage":"--"},"userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko\/20100101 Firefox\/62.0","version":"14.0.3.0"}
{"reqId":"zD816Eixo0of5jb4ddj5","level":0,"time":"2018-10-15T17:47:14+00:00","remoteAddr":"12.34.56.78","user":"freek","app":"core","method":"POST","url":"\/apps\/twofactor_gateway\

Kind regards.

@ChristophWurst
Copy link
Member

Please see #110 (comment) and tell me if you're on the same page with what is a Telegram user ID and a Telegram chat ID. I have the feeling this is being used interchangeably while there's a huge difference.

sending telegram message to CHATID_REMOVED_FOR_PRIVACY

Here, for example. You should see the USER_ID and not chat id. This part confuses me.

@Freekers
Copy link

Telegram User ID: The ID returned by https://t.me/my_id_bot which in my case was the 'CHATID_REMOVED_FOR_PRIVACY' so it should be correct, right?

Telegram Chat ID: The ID of the chat with your bot, which can be obtained by forwarding a message received from your bot to https://telegram.me/get_id_bot .

I am using the same instructions as this guy, who also used the Telegram User ID

@mmartinortiz
Copy link

I've been gathering some definitions about the different terms we are using in this thread, so all we can be in the same line:

  • Bot token: The token is a string along the lines of 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw that is required to authorize the bot and send requests to the Bot API. Source
  • Personal/User Id: The id that identifies a user. This bot provides your user id. (I do not have a reference for this definition)
  • Chat Id: The id that identifies a chat/group. From reddit: Chat ID is your personal ID if you're in private chat (dialogue) with bot and Group/Channel id otherwise. If you want to know personal ID, simply go to chat with @my_id_bot and it will tell you.

With the services/applications I am running, I use the bot token as 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw. As chat id on those services/applications, I'm using my user id because in my case it is a private conversation with my bot (as mentioned in Reddit)

I've tried using the complete token, as well as only the part after the semicolon together with my user id (as equivalent to chat id, because it is a private conversation).

In every case, the debug log obtained with the twofactor_gateway version with extended debug support (obtained here](#126)) does not differ from my previous logs.

@ChristophWurst
Copy link
Member

@mmartinortiz thanks a lot for trying to make this finally clear for everyone 😉

  • Personal/User Id: The id that identifies a user. This bot provides your user id. (I do not have a reference for this definition)

  • Chat Id: The id that identifies a chat/group. From reddit: Chat ID is your personal ID if you're in private chat (dialogue) with bot and Group/Channel id otherwise. If you want to know personal ID, simply go to chat with @my_id_bot and it will tell you.

This part confuses me. Doesn't that say that the user ID and chat ID are the same, at least for personal chats? It's the very same bot that tells you the ID after all.

@Dretech
Copy link
Contributor Author

Dretech commented Oct 16, 2018

Doesn't that say that the user ID and chat ID are the same

In the test script below the user id is the id of the user which is displayed by using the get id bot. I hope this will help to define what the user id is.

?php

$userid="123456789"; # the user id you got by using the get id bot
$key="123456789:CCE8xLJa_sXsj6kxeWaLwxyJ9M368klTnlS"; # the token of the bot you created for using 2fa with nextcloud
$timeout="10";
$text="Test message";

$url="https://api.telegram.org/bot$key/sendMessage?chat_id=$userid&disable_web_page_preview=1&text=$text";

$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);

?>

@Freekers
Copy link

@mmartinortiz thanks a lot for trying to make this finally clear for everyone 😉

  • Personal/User Id: The id that identifies a user. This bot provides your user id. (I do not have a reference for this definition)
  • Chat Id: The id that identifies a chat/group. From reddit: Chat ID is your personal ID if you're in private chat (dialogue) with bot and Group/Channel id otherwise. If you want to know personal ID, simply go to chat with @my_id_bot and it will tell you.

This part confuses me. Doesn't that say that the user ID and chat ID are the same, at least for personal chats? It's the very same bot that tells you the ID after all.

The @my_id_bot has multiple functionalities. It can tell you your Personal/User ID but also the Chat ID of your groupschat.
The @get_id_bot also has multiple functionalities. Next to telling you your Personal/User ID it can also tell you the Chat ID of any chat, not just a groupschat.

Example:
afbeelding

@mmartinortiz
Copy link

@mmartinortiz thanks a lot for trying to make this finally clear for everyone wink

  • Personal/User Id: The id that identifies a user. This bot provides your user id. (I do not have a reference for this definition)
  • Chat Id: The id that identifies a chat/group. From reddit: Chat ID is your personal ID if you're in private chat (dialogue) with bot and Group/Channel id otherwise. If you want to know personal ID, simply go to chat with @my_id_bot and it will tell you.

This part confuses me. Doesn't that say that the user ID and chat ID are the same, at least for personal chats? It's the very same bot that tells you the ID after all.

Exactly, if you are in a private conversation with your bot, then the chat id is the same that the user id.

@ChristophWurst , how can we help to debug further this issue?

@ChristophWurst
Copy link
Member

Exactly, if you are in a private conversation with your bot, then the chat id is the same that the user id.

Perfect! This means we can simplify the setup process a lot. I will try to change this soon.

@ChristophWurst ChristophWurst added this to SELECTED in Christoph's Tasks via automation Oct 23, 2018
@ChristophWurst ChristophWurst changed the title How to use Telegram 2fa Ask user for user id instead of chat id (aka simpler Telegram setup) Oct 23, 2018
@Dretech
Copy link
Contributor Author

Dretech commented Mar 12, 2019

Unfortunately my Telegram ID I entered in the text box, gives the message "Could not verify your code. Please try again." I also tried my phone number, but I get the same error message.

@parreitu
Copy link

Hi, check out this: #226 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants