mirror of
https://github.com/nextcloud/twofactor_gateway.git
synced 2026-04-25 09:05:55 +03:00
[GH-ISSUE #110] Ask user for user id instead of chat id (aka simpler Telegram setup) #36
Labels
No labels
0. to triage
1. to develop
3. to review
blocked
bug
discussion
duplicate
enhancement
enhancement
gateway:signal
gateway:signal
gateway:signal
gateway:sms
gateway:telegram
hacktoberfest
help wanted
invalid
needs info
php
pull-request
question
technical debt
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/twofactor_gateway-nextcloud#36
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Dretech on GitHub (Sep 18, 2018).
Original GitHub issue: https://github.com/nextcloud/twofactor_gateway/issues/110
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:
(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 commented on GitHub (Sep 18, 2018):
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 commented on GitHub (Sep 18, 2018):
Hi Christoph,
Thank you for your quick reply.
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 commented on GitHub (Sep 19, 2018):
This doesn't read like it would cause any problems here.
@Dretech commented on GitHub (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 commented on GitHub (Sep 25, 2018):
Take a look at the admin docs: https://github.com/nextcloud/twofactor_gateway/tree/master/doc/admin#telegram
@Dretech commented on GitHub (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 commented on GitHub (Sep 27, 2018):
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 commented on GitHub (Sep 27, 2018):
After running
occ twofactorauth:gateway:configure telegramI 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).
`
@ChristophWurst commented on GitHub (Sep 28, 2018):
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 commented on GitHub (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.
. My current version of Nextcloud is: 14.0.0
Below you will find today's records of nextcloud.log containing 'Telegram':
@MartinGE47 commented on GitHub (Sep 30, 2018):
I have the same problem. Some one can help us
@ChristophWurst commented on GitHub (Oct 1, 2018):
So somewhere around
github.com/nextcloud/twofactor_gateway@1f855c5568/lib/Service/Gateway/Telegram/Gateway.php (L82-L95).Could you manually check the updates on your bot to see if they contain the event of a new conversation with your user?
@Dretech commented on GitHub (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:
After sending a message to the Nextcloud 2fa bot I created in the Telegram app the status of the Telegram APi is:
The full conents of the json repsonse is:
Tonight I also tested the first version of the Telegram 2fa code I created and that is still working.
@ChristophWurst commented on GitHub (Oct 1, 2018):
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 commented on GitHub (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 commented on GitHub (Oct 2, 2018):
I will try to add more debug logging to the Telegram code to help debug these scenarios.
@Dretech commented on GitHub (Oct 2, 2018):
Thanks
@mmartinortiz commented on GitHub (Oct 5, 2018):
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 IDobtained with theget_idbot, I see the following exception in thenextcloud.log(extract)The value I've introduced is compose by 8 positive integers. I've also tried with the "User Name" provided by the
get_idbot@ChristophWurst commented on GitHub (Oct 6, 2018):
@mmartinortiz please see https://github.com/nextcloud/twofactor_gateway/pull/126, test the provided package and report back the debug log entries. Thanks.
@mmartinortiz commented on GitHub (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.@ChristophWurst commented on GitHub (Oct 6, 2018):
Did you actually set the log level to 0/debug?
@mmartinortiz commented on GitHub (Oct 7, 2018):
The rest of the entries related to
"Scss is disabled for...". I've also updated the log for my previous comment.@ChristophWurst commented on GitHub (Oct 7, 2018):
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->setUserValueis 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 commented on GitHub (Oct 7, 2018):
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 commented on GitHub (Oct 7, 2018):
For the sake of clarity, I'll list the steps I've followed for the logs provided:
twofactor_gatewayfrom my Nextcloud serverappsfoldertwofactor_gatewayapplicationloglevel => 0onconfig.phptwofactor_gatewayapplication with my bot token from the command lineenablethe Telegram gateway and introduce my Chat Id.nextcloud.logfileSince 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)//:
I've used the logged
<bot token>for accessing manually to the URLhttps://api.telegram.org/bot<bot_token>/getupdatesfor checking that it is correct.@ChristophWurst commented on GitHub (Oct 7, 2018):
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.
@mmartinortiz commented on GitHub (Oct 8, 2018):
The chat with the bot is currently receiving messages from other applications. What do you exactly mean with restart?. When I've used the same token and chat id for other applications, I never had to restart the conversation with the bot.
@ChristophWurst commented on GitHub (Oct 8, 2018):
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 commented on GitHub (Oct 9, 2018):
In few words, the mechanism to get the bot up and running is what you described:
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 commented on GitHub (Oct 9, 2018):
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.
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 commented on GitHub (Oct 9, 2018):
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?
From the last debug line
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 commented on GitHub (Oct 9, 2018):
No. There is one bot for all users.
@ChristophWurst commented on GitHub (Oct 9, 2018):
How did you actually obtain the chat ID?
@Dretech commented on GitHub (Oct 9, 2018):
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 commented on GitHub (Oct 9, 2018):
@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"
@ChristophWurst, Can I ask for the technical reasons for that?
Using the get id bot (as stated on the admin docs)
@ChristophWurst commented on GitHub (Oct 10, 2018):
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 commented on GitHub (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.
@ChristophWurst commented on GitHub (Oct 10, 2018):
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 commented on GitHub (Oct 10, 2018):
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 commented on GitHub (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: https://github.com/nextcloud/twofactor_gateway/pull/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
TelegramResponseExceptionnot found, there is not much from what I can see that goes wrong:Kind regards.
@ChristophWurst commented on GitHub (Oct 15, 2018):
Please see https://github.com/nextcloud/twofactor_gateway/issues/110#issuecomment-428452473 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.
Here, for example. You should see the USER_ID and not chat id. This part confuses me.
@Freekers commented on GitHub (Oct 15, 2018):
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 commented on GitHub (Oct 16, 2018):
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:
110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsawthat is required to authorize the bot and send requests to the Bot API. SourceWith 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](https://github.com/nextcloud/twofactor_gateway/pull/126)) does not differ from my previous logs.
@ChristophWurst commented on GitHub (Oct 16, 2018):
@mmartinortiz thanks a lot for trying to make this finally clear for everyone 😉
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 commented on GitHub (Oct 16, 2018):
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.
@Freekers commented on GitHub (Oct 17, 2018):
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:

@mmartinortiz commented on GitHub (Oct 22, 2018):
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 commented on GitHub (Oct 23, 2018):
Perfect! This means we can simplify the setup process a lot. I will try to change this soon.
@Dretech commented on GitHub (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 commented on GitHub (Apr 26, 2019):
Hi, check out this: https://github.com/nextcloud/twofactor_gateway/issues/226#issuecomment-487092287