Пример #1
0
        public OperationResponse SendMessage(string title, string content, string senderLoginName, string receiverDisplayName)
        {
            Contact sender = contactRepository.GetContactByLoginName(senderLoginName);

            if (sender == null)
            {
                return(OperationResponse.Error("未获取到发件人信息"));
            }
            Contact receiver = contactRepository.GetContactByDisplayName(receiverDisplayName);

            if (receiver == null)
            {
                return(OperationResponse.Error("未获取到收件人信息"));
            }
            Message message = new Message(title, content, sender, receiver);

            if (sendMessageService.SendMessage(message))
            {
                messageRepository.AddMessage(message);
                return(OperationResponse.Success("发送成功"));
                //return Context.Commit();
            }
            else
            {
                return(OperationResponse.Error("发送失败"));
            }
        }
Пример #2
0
        private async Task HandleSuccess(Chat chat, string shortName, Departure departures)
        {
            var message = GetFormattedDepartureMessage(departures);

            var inlineButtons       = new List <List <InlineKeyboardButton> >();
            var withLoadMoreCommand = departures.DepartureResultState == DepartureResultState.Ok &&
                                      departures.RequestedLimit == StopService.DepartureShortLimit;

            if (withLoadMoreCommand)
            {
                var button = new InlineKeyboardButton
                {
                    Text         = Strings.ShowDeparturesCommand_LoadMoreDepartures,
                    CallbackData = $"{Commands.QueryLoadMoreCommand}{Commands.QueryDataSeparator}{shortName}"
                };
                inlineButtons.Add(new List <InlineKeyboardButton> {
                    button
                });
            }

            if (!await _favoriteStopService.IsFavoriteStop(chat.Id.ToString(), shortName))
            {
                var button = new InlineKeyboardButton
                {
                    Text         = Strings.ShowDeparturesCommand_AddToFavorites,
                    CallbackData = $"{Commands.QueryAddToFavoriteCommand}{Commands.QueryDataSeparator}{shortName}",
                };
                inlineButtons.Add(new List <InlineKeyboardButton> {
                    button
                });
            }

            var markup = new InlineKeyboardMarkup(inlineButtons);
            await _sendMessageService.SendMessage(chat, message, markup);
        }
        public async Task ShowFavoriteStops(Chat chat)
        {
            var stops = await _favoriteStopService.GetFavoriteStops(chat.Id.ToString());

            var keyboardMarkup = CreateReplyKeyboardMarkup(stops.Select(_ => _.ShortName));
            await _sendMessageService.SendMessage(chat, Strings.FavoriteStopsCommand_RefreshFavorties, keyboardMarkup);
        }
Пример #4
0
        static void Main(string[] args)
        {
            ServiceProvider serviceProvider = new ServiceCollection()

                                              .AddSingleton <ISendMessageService, SendMessageService>()
                                              .BuildServiceProvider();

            ISendMessageService sendMessageServ = serviceProvider.GetService <ISendMessageService>();

            sendMessageServ.SendMessage(args);

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Пример #5
0
 public int SendMessage(string message, string MQName, bool needResponse = true)
 {
     if ((address != null) && (Binding != null))
     {
         using (ChannelFactory <ISendMessageService> channel = new ChannelFactory <ISendMessageService>(Binding, address))
         {
             ISendMessageService service = channel.CreateChannel();
             return(service.SendMessage(message, MQName, needResponse));
         }
     }
     else
     {
         return(-1);
     }
 }
        //private static void Main(string[] args)
        //{
        //    BotClient = new TelegramBotClient(Config["TelegramBotToken"]);
        //    SendMessageService = new SendMessageService(BotClient);

        //    BotClient.OnMessage += BotClientOnOnMessage;
        //    BotClient.OnCallbackQuery += BotClientOnOnCallbackQuery;
        //    BotClient.StartReceiving();

        //    Console.WriteLine("Press any key to exit");
        //    Console.ReadKey();

        //    BotClient.StopReceiving();

        //    //await InitDvbBotDBAsync();
        //}

        public async Task ComputeMessage(Message messsage)
        {
            try
            {
                if (string.IsNullOrEmpty(messsage.Text))
                {
                    return;
                }

                var message = messsage.Text.Trim();
                if (string.IsNullOrEmpty(message))
                {
                    return;
                }

                var splittedMessage = message.Split(" ");
                var shortName       = splittedMessage.Length > 1 ? splittedMessage[1] : null;

                if (splittedMessage[0] == Commands.Commands.CommandStart)
                {
                    // print start message
                    await _sendMessageService.SendMessage(messsage.Chat, Strings.Programm_StartMessage);

                    await _sendMessageService.SendMessage(messsage.Chat, Strings.Programm_HelpMessage);
                }
                else if (splittedMessage[0] == Commands.Commands.CommandHelp)
                {
                    // print help message
                    await _sendMessageService.SendMessage(messsage.Chat, Strings.Programm_HelpMessage);
                }
                else if (splittedMessage[0] == Commands.Commands.CommandAddStation)
                {
                    // add fav
                    if (string.IsNullOrEmpty(shortName))
                    {
                        var m = string.Format(Strings.Program_SpecifyStop, Commands.Commands.CommandAddStation);
                        await _sendMessageService.SendMessage(messsage.Chat, m);

                        return;
                    }

                    var command = new FavoriteStopsCommand(_sendMessageService, _favoriteStopService);
                    await command.AddFavoriteStop(messsage.Chat, shortName);
                }
                else if (splittedMessage[0] == Commands.Commands.CommandRemoveStation)
                {
                    // remove fav
                    if (string.IsNullOrEmpty(shortName))
                    {
                        var m = string.Format(Strings.Program_SpecifyStop, Commands.Commands.CommandRemoveStation);
                        await _sendMessageService.SendMessage(messsage.Chat, m);

                        return;
                    }

                    var command = new FavoriteStopsCommand(_sendMessageService, _favoriteStopService);
                    await command.RemoveFavoriteStop(messsage.Chat, shortName);
                }
                else if (splittedMessage[0] == Commands.Commands.CommandShowFavoriteStations)
                {
                    // refresh keys
                    var command = new FavoriteStopsCommand(_sendMessageService, _favoriteStopService);
                    await command.ShowFavoriteStops(messsage.Chat);
                }
                else if (splittedMessage[0].StartsWith("/"))
                {
                    // invalid command
                    await _sendMessageService.SendMessage(messsage.Chat, Strings.Program_InvalidCommand);

                    await _sendMessageService.SendMessage(messsage.Chat, Strings.Programm_HelpMessage);
                }
                else
                {
                    // send departures
                    var stopShortName = splittedMessage[0];
                    var command       = new ShowDeparturesCommand(_sendMessageService, _stopService, _favoriteStopService);
                    await command.ShowDepartures(messsage.Chat, stopShortName,
                                                 StopService.DepartureShortLimit);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }