public override async Task <bool> SendMessage(string message) { try { long randomId = Helpers.GenerateRandomLong(); MessageModelUndelivered undeliveredMessage = new MessageModelUndelivered() { MessageType = MessageModelUndelivered.Type.Text, Text = message, Timestamp = DateTime.Now, RandomId = randomId }; ProcessNewMessage(undeliveredMessage); // TODO: npe? messages_SentMessage sentMessage = await session.Api.messages_sendMessage(InputPeer, message, randomId); int date, id, pts, seq; if (sentMessage.Constructor == Constructor.messages_sentMessage) { Messages_sentMessageConstructor sent = (Messages_sentMessageConstructor)sentMessage; id = sent.id; pts = sent.pts; seq = sent.seq; date = sent.date; } else if (sentMessage.Constructor == Constructor.messages_sentMessageLink) { Messages_sentMessageLinkConstructor sent = (Messages_sentMessageLinkConstructor)sentMessage; id = sent.id; pts = sent.pts; seq = sent.seq; date = sent.date; List <contacts_Link> links = sent.links; // TODO: process links } else { logger.error("unknown sentMessage constructor"); return(false); } if (session.Updates.processUpdatePtsSeqDate(pts, seq, date) == false) { messages.Remove(undeliveredMessage); return(false); } ; int messageIndex = messages.IndexOf(undeliveredMessage); if (messageIndex != -1) { messages[messageIndex] = new MessageModelDelivered(TL.message(id, session.SelfId, dialog.peer, true, true, date, message, TL.messageMediaEmpty())); } else { logger.error("not found undelivered message to confirmation"); } TelegramSession.Instance.Dialogs.Model.UpDialog(this); return(true); } catch (Exception ex) { logger.error("exception {0}", ex); return(false); } }
private void ProcessUpdate(UpdateShortChatMessageConstructor update) { logger.info("processing short chat message: {0}", update); if (!processUpdatePtsSeqDate(update.pts, update.seq, update.date)) { return; } Message message = TL.message(update.id, update.from_id, TL.peerChat(update.chat_id), false, true, update.date, update.message, TL.messageMediaEmpty()); NewMessageEvent(message); }