Skip to content

.NET Standard Library for Webex Teams API

License

Notifications You must be signed in to change notification settings

wgraham17/WxTeamsSharp

 
 

Repository files navigation

Build status

WxTeamsSharp: A Webex Teams .NET C# Library

A .NET Standard 2.0 Library to help developers communicate easily with the Webex Teams API.

Available on GitHub and NuGet:

Install-Package WxTeamsSharp

Notice: 2.0.0 is a major update with a paradigm shift from static to DI. You will want to check both of the examples for ways to get started.

Basic Usage

Take a look at the Integration Tests and Example Projects. They should cover most of the ways you can use the library. If all else fails, there's always the API Reference!

Example

DI Setup

Be sure to check out the WxTeamsWebhookReciever for an ASP.NET Core example and WxTeamsConsoleBot for .NET Core Console example.

 public void ConfigureServices(IServiceCollection services)
        {
            ... 

            services.AddWxTeamsSharp();

            ...
        }

Code Example

public class TeamsService
    {
        private readonly IWxTeamsApi _wxTeamsApi;

        public TeamsService(IConfiguration configuration, IWxTeamsApi wxTeamsApi)
        {
            var token = configuration.GetSection("BotToken").Value;
            _wxTeamsApi = wxTeamsApi;
            _wxTeamsApi.Initialize(token);
        }

        public async Task HandleCreatedMessage(WebhookData<Message> webhookData)
        {
            var person = await _wxTeamsApi.GetUserAsync(webhookData.Data.AuthorId);
            var room = await _wxTeamsApi.CreateRoomAsync("test");
            await room.DeleteAsync();

            // The Message Created event will also trigger off a message created by the bot
            // Unless you want to end up with an endless loop of messages, you have to make
            // sure you're not responding to yourself.

            // At the same time, it's probably a good idea to consider not letting your bot
            // respond to other bots at all. Only people.
            if (person.Type != PersonType.Bot)
            {
                var message = await _wxTeamsApi.GetMessageAsync(webhookData.Data.Id);

                var newMessage = MessageBuilder.New()
                    .SendToRoom(message.RoomId)
                    .WithMarkdown("**Hi!**")
                    .Build();

                await _wxTeamsApi.SendMessageAsync(newMessage);
            }
        }
    }

About

.NET Standard Library for Webex Teams API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%