Esempio n. 1
0
 public VKBot(IOptions <VKBotOptions> options)
 {
     vkService = new VKService(_logger);
     _options  = options.Value;
 }
Esempio n. 2
0
        public async Task <string> sendRequest(IOutgoingMessage message, string method, VKBotOptions options)
        {
            var urlBuilder = new UriBuilder(_url)
            {
                Path  = $"method/{method}",
                Query = $"group_id={options.groupId}&access_token={options.token}&v={options.apiVersion}"
            };

            _logger.Log(NLog.LogLevel.Info, urlBuilder);
            var values = message.GetType()
                         .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                         .Select(t => new { key = t.Name, value = t.GetValue(message, null) })
                         .Where(t => t.value != null)
                         .ToDictionary(t => t.key, t => t.value.ToString());
            var content  = new FormUrlEncodedContent(values);
            var response = await _httpClient.PostAsync(urlBuilder.Uri, content);

            var responseBody = await response.Content.ReadAsStringAsync();

            _logger.Log(NLog.LogLevel.Info, responseBody);
            return(responseBody);
        }