private MatrixRequestError sendRoomMessage(MatrixAPIPendingEvent msg)
        {
            JObject            msgData = ObjectToJson(msg.content);
            JObject            result;
            MatrixRequestError error = mbackend.Put(String.Format("/_matrix/client/r0/rooms/{0}/send/{1}/{2}", System.Uri.EscapeDataString(msg.room_id), msg.type, msg.txnId), true, msgData, out result);

                        #if DEBUG
            if (!error.IsOk)
            {
                Console.WriteLine(error.GetErrorString());
            }
                        #endif
            return(error);
        }
        public void RoomMessageSend(string roomid, string type, MatrixMRoomMessage message)
        {
            bool collision            = true;
            MatrixAPIPendingEvent evt = new MatrixAPIPendingEvent();

            evt.room_id = roomid;
            evt.type    = type;
            evt.content = message;
            if (((MatrixMRoomMessage)evt.content).body == null)
            {
                throw new Exception("Missing body in message");
            }
            while (collision)
            {
                evt.txnId = rng.Next(1, 64);
                collision = pendingMessages.FirstOrDefault(x => x.txnId == evt.txnId) != default(MatrixAPIPendingEvent);
            }
            pendingMessages.Enqueue(evt);
            if (IsAS)
            {
                FlushMessageQueue();
            }
        }