steavy29 / Telegram.Net

Telegram (http://telegram.org) client library implemented in C#.
17 stars 6 forks source link

How to send messages to the group? #6

Closed andrew-maksimov closed 8 years ago

andrew-maksimov commented 8 years ago
[TestMethod]
        public async Task CreateChatAndSendMessage()
        {
            var client = await InitializeClient();

            var chatName = Guid.NewGuid().ToString();
            var statedMessage = await client.CreateChat(chatName, new List<string> { NumberToSendMessage });

            var createdChat = GetChatFromStatedMessage(statedMessage);

            Assert.AreEqual(chatName, createdChat.title);
            Assert.AreEqual(2, createdChat.participants_count);

            await client.SendMessage(createdChat.id, "Test message to group");
        }

Test method CreateChatAndSendMessage threw exception: System.InvalidOperationException: PEER_ID_INVALID

steavy29 commented 8 years ago

Did you configure NumberToAuthenticate and NumberToSendMessage in app.config with valid phone numbers?

andrew-maksimov commented 8 years ago

Try to run my test at. (the code in the first comment)

andrew-maksimov commented 8 years ago

Numbers phone valid. All standard tests are performed.

Exception occurs only when you try to send a message to a group chat.

steavy29 commented 8 years ago

Sorry for big delay. I`ll investigate this in the next few days.

andrew-maksimov commented 8 years ago

I deal with this issue. The reason was my inattention.

In order that would poison the message to a group chat, need to use InputPeerChatConstructor instead InputPeerContactConstructor in SendMessageRequest.

steavy29 commented 8 years ago

I see. I'm currently making some refactorings to make such errors not possible. I think there will be no method SendMessage in api. But instead you'll just create appropriate request and submit it. Need few days more to finish.