Example #1
0
        public async Task <bool> Execute(string command)
        {
            var conversations = await _conversationService.AllAsync();

            _botLogger.LogInfo("");
            foreach (var conversation in conversations.Items)
            {
                _botLogger.LogInfo($"ID: {conversation.ConversationId}\tName:\t{conversation.DisplayName}");
            }
            _botLogger.LogInfo("");
            var convId = _botLogger.ReadLine("Enter conversation ID you want to say:");
            var target = conversations.Items.FirstOrDefault(t => t.ConversationId.ToString() == convId);

            if (target == null)
            {
                _botLogger.LogDanger($"Can't find conversation with ID: {convId}");
                return(true);
            }
            var toSay = _botLogger.ReadLine($"Enter the message you want to send to '{target.DisplayName}':");

            if (string.IsNullOrWhiteSpace(toSay))
            {
                _botLogger.LogDanger("Can't send empty content.");
                return(true);
            }
            var encrypted = _aes.OpenSSLEncrypt(toSay, _eventSyncer.Contacts.FirstOrDefault(t => t.ConversationId == target.ConversationId)?.AesKey);
            await _conversationService.SendMessageAsync(encrypted, target.ConversationId);

            _botLogger.LogSuccess("Sent.");
            return(true);
        }
Example #2
0
        public string AskServerAddress()
        {
            var cached = _settingsService["ServerAddress"] as string;

            if (!string.IsNullOrWhiteSpace(cached))
            {
                return(cached);
            }
            _botLogger.LogInfo("Welcome! Please enter the server address of Kahla.");
            var result = _botLogger.ReadLine("\r\nEnter 1 for production\r\nEnter 2 for staging\r\nFor other server, enter like: https://server.kahla.app\r\n");

            if (result.Trim() == 1.ToString())
            {
                return("https://server.kahla.app");
            }
            else if (result.Trim() == 2.ToString())
            {
                return("https://staging.server.kahla.app");
            }
            else
            {
                return(result);
            }
        }