Читать на русском языке (Russian)
A fully asynchronous C#/.NET library for interacting with the OpenVK API. Built with ease of use and performance in mind, targeting .NET Standard 1.1 to ensure maximum compatibility across diverse platforms (including .NET Framework, .NET Core, Xamarin, and Unity).
💡 Looking for API Reference? Check out the Documentation Website.
- Fully Asynchronous: All network requests and disk operations are async-first.
- Strongly Typed: Complete mapping of OpenVK models (Profiles, Groups, Messages, Video, Attachments, etc.) to C# classes with clean JSON serialization.
- Robust Long Poll Service: High-performance background listening of server events, including:
- New message events.
- Real-time typing indicators (
User is typing...) in private dialogues. - Automatic session key refreshing and retry logic on connection dropouts.
Install the package via NuGet Package Manager CLI:
dotnet add package OpenVkNetApiOr search for OpenVkNetApi in the Visual Studio NuGet Package Manager.
using OpenVkNetApi;
// Create the API client for your target OpenVK instance
var api = new OpenVkApi("https://api.openvk.org");
// Authorize with username and password
var authInfo = await api.AuthorizeAsync("your_username", "your_password");
Console.WriteLine($"Authorized successfully! Access Token: {api.AccessToken}");using OpenVkNetApi.Models.RequestParameters.Messages;
var messageParams = new MessagesSendParams
{
PeerId = 12345, // Target user or chat ID
Message = "Hello from OpenVkNetApi!"
};
var sentIds = await api.Messages.SendAsync(messageParams);
Console.WriteLine($"Message sent! ID: {sentIds[0]}");Listen to incoming messages and typing status in real-time:
using System;
using System.Threading;
using OpenVkNetApi.Services;
// Initialize the service (uses internal HTTP client optimized for background polling)
using var longPoll = api.LongPoll;
// Subscribe to events
longPoll.OnMessageNew += (sender, e) =>
{
Console.WriteLine($"New message from {e.Message.FromId}: {e.Message.Text}");
};
longPoll.OnUserTyping += (sender, e) =>
{
Console.WriteLine($"User {e.UserId} is typing...");
};
longPoll.OnError += (sender, e) =>
{
Console.WriteLine($"Long Poll Error: {e.ErrorMessage}");
};
// Start listening (Async Loop)
var cts = new CancellationTokenSource();
Console.WriteLine("Listening for events... Press Ctrl+C to stop.");
await longPoll.StartAsync(cts.Token);This project is licensed under the MIT License - see the LICENSE file for details.