示例#1
0
        public async Task <MessageSendResult> Send(INeedSend message)
        {
            ChatId destId = null;
            var    user   = _dbContext.Users.SingleOrDefault(
                x => x.Username != null && x.Username.ToLower() == message.To.ToLower() ||
                x.PhoneNumber == _phoneHelper.Clear(message.To.ToLower()));

            if (user == null)
            {
                return(new MessageSendResult()
                {
                    Message = message,
                    IsSuccess = false,
                    Error = $"Не могу отправить сообщение пользователю {message.To}, т.к.он не добавил бота в телеграмме"
                });
            }
            destId = new ChatId(user.ChatId);
            var bot = new Telegram.Bot.TelegramBotClient(_configService.Config.BotApiKey);
            await bot.SendTextMessageAsync(destId, message.Text);

            return(new MessageSendResult()
            {
                Message = message,
                IsSuccess = true
            });
        }
示例#2
0
        public async Task <MessageSendResult> Send(INeedSend message)
        {
            var accountSid = _configService.Config.Twillo.Sid;
            var authToken  = _configService.Config.Twillo.Token;

            TwilioClient.Init(accountSid, authToken);

            await MessageResource.CreateAsync(
                to : new PhoneNumber(_phoneHelper.GetPhoneNumberForTwilio(message.To)),
                from : new PhoneNumber(_configService.Config.Twillo.PhoneNumber),
                body : message.Text);

            return(new MessageSendResult()
            {
                Message = message,
                IsSuccess = true
            });
        }