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

Why I cannot create this json format to send text? #2843

Open
SnapdragonLee opened this issue Apr 9, 2024 · 8 comments
Open

Why I cannot create this json format to send text? #2843

SnapdragonLee opened this issue Apr 9, 2024 · 8 comments

Comments

@SnapdragonLee
Copy link

SnapdragonLee commented Apr 9, 2024

Because of the simple event handler architechture in python, I'm using tdjson to send text/file/photo to myself.

td_send({
            "@type": "sendMessage",
            "chat_id": '',
            "input_message_content": {
                "@type": "inputMessageText",
                "text": {
                    "@type": "formattedText",
                    "text": "Hello, this is a test message."
                }
            }
        })

Why there's no return/sending behavior or any traceback error after excuted this command? Actually, this text has not been sent to my chat.

@SnapdragonLee
Copy link
Author

SnapdragonLee commented Apr 9, 2024

If I change chat_id to any other chats, or change type to photo/file no behaviors either.

@SnapdragonLee SnapdragonLee changed the title Why I cannot create this json format to sned text? Why I cannot create this json format to send text? Apr 9, 2024
@levlam
Copy link
Contributor

levlam commented Apr 10, 2024

You can use only identifiers received from TDLib, therefore you must receive the chat_id from TDLib before you can use it.

Additionally, you can check TDLib logs to see requests received by TDLib and their responses.

@SnapdragonLee
Copy link
Author

You can use only identifiers received from TDLib, therefore you must receive the chat_id from TDLib before you can use it.

Additionally, you can check TDLib logs to see requests received by TDLib and their responses.

Thanks for the reply. From my side, I could see the identifiers in a 10 digits format, and I have handled the json event each time I send to myself on other clients.

For the TDLib, what level of logs should I use? level 2? I may have a try to redirect stdout to a file.

@levlam
Copy link
Contributor

levlam commented Apr 10, 2024

You need level 3 or bigger to see all requests in the log.

@SnapdragonLee
Copy link
Author

SnapdragonLee commented Apr 26, 2024

OK, I have do some tests on daemon thread.

time.sleep(3)
    td_send({
        # '@type': 'loadChats',
        # 'limit': 1

        '@type': 'getChat',
        'chat_id': {19xxxxxxxxx}
    })

    time.sleep(3)
    td_send({
        "@type": "sendMessage",
        "chat_id": 19xxxxxxxxx,
        "input_message_content": {
            "@type": "inputMessageText",
            "text": {
                "@type": "formattedText",
                "text": "Hello, this is a test message."
            }
        }
    })

The first one, loadChats and limit set to 1, I could send this message. But for the second, openChat or getChat, the log in severity 3 reports that Chat is not found with a 400 return. Why I got this thing? Just a little bit confusing.

@levlam
Copy link
Contributor

levlam commented Apr 26, 2024

A "Chat not found" error means that you are trying to pass a hardcoded chat identifier to TDLib. You can only use identifiers received from the same TDLIb instance programmatically.

@SnapdragonLee
Copy link
Author

I'm sorry that I may not get you. I just wanna send something to 'Saved Message' by TdLib. How could I manage this before sent sendMessage to target chat_id: 19xxxxxxxxx? What function should I call for receiving the chat_id?

@levlam
Copy link
Contributor

levlam commented Apr 29, 2024

You need to use getMe to get the current user, then use createPrivateChat with received user_id to create the chat with self, and then use received chat identifier to send messages.

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

No branches or pull requests

2 participants