using System; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.Sockets.Version1; namespace Samples { public class Greeter : ISocket { #region IPlugin public string Name => "Sample Greeter Socket Plugin"; public string Description => "This plugin will demonstrate a simple socket plugin which supports sending a message to a user"; } public void Initialize() { } #endregion #region ISocket public string SocketName => "greeter"; public void SetController(ISocketController controller) { controller.Clients.Received += (sender, e) => { // if this was a greting message, let's process it if (e.MessageName == "greet") { // get the associated recipient user // data passed from the client side is available on the dynamic MessageData object var to = Telligent.Evolution.Extensibility.Apis.Get().Users.Get(new Telligent.Evolution.Extensibility.Api.Version1.UsersGetOptions { Username = (string)e.MessageData.Recipient }); // get the sender user var from = Telligent.Evolution.Extensibility.Apis.Get().Get(new Telligent.Evolution.Extensibility.Api.Version1.UsersGetOptions { Id = e.UserId }); // send a new message to the recipient controller.Clients.Send(to.Id.GetValueOrDefault(), "greet", new { Message = String.Format("Hello {0}, from {1}", to.DisplayName, from.DisplayName) }); } }; } #endregion } }