/// <inheritdoc />
        public async Task Handle(ServiceHookEventBase serviceHookEvent, Subscription subscription)
        {
            var ev = serviceHookEvent as ServiceHookEvent <ApprovalResource>;

            ev.ThrowIfNull(nameof(serviceHookEvent));
            subscription.ThrowIfNull(nameof(subscription));

            var address = new Address(string.Empty, subscription.ChannelId, subscription.UserId, string.Empty, string.Empty);
            var botData = this.botDataFactory.Create(address);
            await botData.LoadAsync(CancellationToken.None);

            var data = botData.UserData.GetValue <UserData>("userData");

            MicrosoftAppCredentials.TrustServiceUrl(subscription.ServiceUri.AbsoluteUri);
            var client = new ConnectorClient(subscription.ServiceUri, this.credentials.MicrosoftAppId, this.credentials.MicrosoftAppPassword);

            var conversation = subscription.ChannelId.Equals(ChannelIds.Msteams)
                ? client.Conversations.CreateOrGetDirectConversation(
                new ChannelAccount(subscription.BotId, subscription.BotName),
                new ChannelAccount(subscription.RecipientId, subscription.RecipientName),
                subscription.TenantId)
                : client.Conversations.CreateDirectConversation(
                new ChannelAccount(subscription.BotId, subscription.BotName),
                new ChannelAccount(subscription.RecipientId, subscription.RecipientName));

            var activity = new Activity
            {
                Conversation = new ConversationAccount
                {
                    Id = conversation.Id
                },
                From      = new ChannelAccount(subscription.BotId, subscription.BotName),
                Recipient = new ChannelAccount(subscription.RecipientId, subscription.RecipientName),
                Text      = Labels.PendingApproval,
                Type      = ActivityTypes.Message
            };

            var card = new ApprovalCard(data.Account, ev.Resource.Approval, data.TeamProject);

            activity.Attachments.Add(card);

            client.Conversations.SendToConversation(activity, conversation.Id);
        }
Beispiel #2
0
        public void Constructor()
        {
            var approval = new ReleaseApproval
            {
                ReleaseDefinitionReference = new ReleaseDefinitionShallowReference {
                    Id = 3, Name = "Release Def 3"
                },
                ReleaseEnvironmentReference = new ReleaseEnvironmentShallowReference {
                    Id = 2, Name = "DEV"
                },
                ReleaseReference = new ReleaseShallowReference {
                    Id = 1, Name = "release-1"
                }
            };

            var target = new ApprovalCard("account1", approval, "teamproject1");

            target.Subtitle.Should().Be("release-1");
            target.Text.Should().Be("DEV");
            target.Title.Should().Be("Release Def 3");
            target.Tap.Type.Should().Be(ActionTypes.OpenUrl);
            target.Tap.Value.Should().Be("https://account1.visualstudio.com/teamproject1/_release?definitionId=3&_a=release-summary&releaseId=1");
        }