예제 #1
0
        /// <summary>
        /// Deletes a contact from the list.
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public async Task <bool> DeleteContactAsync(Models.Contact contact)
        {
            await ConnectAsync();

            bool deleteSuccessfully = false;

            try
            {
                ContactsLink contactsLink = await _client.DeleteContact(new InputUserContactConstructor(contact.Id));

                deleteSuccessfully = true;
            }
            catch (TelegramReqestException ex)
            {
                _logger.Error($"The contact with id `{contact.Id}` can not be found in contacts", ex);
            }
            return(deleteSuccessfully);
        }
예제 #2
0
        public async Task <Models.SentMessage> SendMessageToContact(Models.Contact contact, string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return(null);
            }

            await ConnectAsync();

            SentMessage sentMessage = null;

            if (contact.IsForeign)
            {
                sentMessage = await _client.SendMessage(new InputPeerForeignConstructor(contact.Id, contact.AccessHash), message);
            }
            else
            {
                sentMessage = await _client.SendMessage(new InputPeerContactConstructor(contact.Id), message);
            }
            return((Models.SentMessage)sentMessage);
        }