Pre-release | Stable Release | |
---|---|---|
Rocket.Chat.Net | ||
Rocket.Chat.Net.Bot |
A Rocket.Chat real-time, managed, .Net driver, and bot.
Not compatible with 0.36.0, 0.37.0, 0.37.1, see Silvenga#2 Waiting for things to settle down.
const string username = "m@silvenga.com";
const string password = "silverlight";
const string rocketServerUrl = "demo.rocket.chat:3000";
const bool useSsl = false;
ILoginOption loginOption = new LdapLoginOption
{
Username = username,
Password = password
};
IRocketChatDriver driver = new RocketChatDriver(rocketServerUrl, useSsl);
await driver.ConnectAsync(); // Connect to server
await driver.LoginAsync(loginOption); // Login via LDAP
await driver.SubscribeToRoomAsync(); // Listen on all rooms
driver.MessageReceived += Console.WriteLine;
var generalRoomIdResult = await driver.GetRoomIdAsync("general");
if (generalRoomIdResult.HasError)
{
throw new Exception("Could not find room by name.");
}
var generalRoomId = generalRoomIdResult.Result;
await driver.SendMessageAsync("message", generalRoomId);
const string username = "m@silvenga.com";
const string password = "silverlight";
const string rocketServerUrl = "dev0:3000"; // just the host and port
const bool useSsl = false; // Basically use ws or wss.
// Create the bot - an abstraction of the driver
RocketChatBot bot = new RocketChatBot(rocketServerUrl, useSsl);
// Connect to Rocket.Chat
await bot.ConnectAsync();
// Login
ILoginOption loginOption = new EmailLoginOption
{
Email = username,
Password = password
};
await bot.LoginAsync(loginOption);
// Start listening for messages
await bot.SubscribeAsync();
// Add possible responses to be checked in order
// This is not thead safe, FYI
IBotResponse giphyResponse = new GiphyResponse();
bot.AddResponse(giphyResponse);
// And that's it
// Checkout GiphyResponse in the example project for more info.