Exemple #1
0
        public void ConversationResultInitsWithNoArgs()
        {
            var convosResult = new ConversationsResult();

            Assert.NotNull(convosResult);
            Assert.IsType <ConversationsResult>(convosResult);
        }
        /// <summary>
        /// Lists the Conversations in which this bot has participated for a given channel server. The
        /// channel server returns results in pages and each page will include a `continuationToken`
        /// that can be used to fetch the next page of results from the server.
        /// </summary>
        /// <param name="context">The context object for the turn.</param>
        /// <param name="continuationToken">(Optional) token used to fetch the next page of results
        /// from the channel server. This should be left as `null` to retrieve the first page
        /// of results.</param>
        /// <returns>List of Members of the current conversation</returns>
        /// <remarks>
        /// This overload may be called during standard Activity processing, at which point the Bot's
        /// service URL and credentials that are part of the current activity processing pipeline
        /// will be used.
        /// </remarks>
        public async Task <ConversationsResult> GetConversations(ITurnContext context, string continuationToken = null)
        {
            var connectorClient         = context.Services.Get <IConnectorClient>();
            ConversationsResult results = await connectorClient.Conversations.GetConversationsAsync(continuationToken).ConfigureAwait(false);

            return(results);
        }
        protected override Task <ConversationsResult> OnGetConversationsAsync(ClaimsIdentity claimsIdentity, string conversationId, string continuationToken = null, CancellationToken cancellationToken = default)
        {
            //return base.OnGetConversationsAsync(claimsIdentity, conversationId, continuationToken, cancellationToken);
            this._logger.LogWarning($"attempt to invoke {nameof(OnGetConversationsAsync)} method, but this method is not implemented");
            var result = new ConversationsResult {
            };

            return(Task.FromResult(result));
        }
        /// <summary>
        /// Lists the Conversations in which this bot has participated for a given channel server. The
        /// channel server returns results in pages and each page will include a `continuationToken`
        /// that can be used to fetch the next page of results from the server.
        /// </summary>
        /// <param name="serviceUrl">The URL of the channel server to query.  This can be retrieved
        /// from `context.activity.serviceUrl`. </param>
        /// <param name="credentials">The credentials needed for the Bot to connect to the services.</param>
        /// <param name="continuationToken">(Optional) token used to fetch the next page of results
        /// from the channel server. This should be left as `null` to retrieve the first page
        /// of results.</param>
        /// <returns>List of Members of the current conversation</returns>
        /// <remarks>
        /// This overload may be called from outside the context of a conversation, as only the
        /// Bot's ServiceUrl and credentials are required.
        /// </remarks>
        public async Task <ConversationsResult> GetConversations(string serviceUrl, MicrosoftAppCredentials credentials, string continuationToken = null)
        {
            if (string.IsNullOrWhiteSpace(serviceUrl))
            {
                throw new ArgumentNullException(nameof(serviceUrl));
            }

            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            var connectorClient         = CreateConnectorClient(serviceUrl, credentials);
            ConversationsResult results = await connectorClient.Conversations.GetConversationsAsync(continuationToken).ConfigureAwait(false);

            return(results);
        }
Exemple #5
0
        public void ConversationResultInits()
        {
            var continuationToken = "continuationToken";
            var conversations     = new List <ConversationMembers>()
            {
                new ConversationMembers("id1", new List <ChannelAccount>()),
                new ConversationMembers("id2", new List <ChannelAccount>())
            };

            var convosResult = new ConversationsResult(continuationToken, conversations);

            Assert.NotNull(convosResult);
            Assert.IsType <ConversationsResult>(convosResult);
            Assert.Equal(continuationToken, convosResult.ContinuationToken);
            Assert.Equal(conversations, convosResult.Conversations);
            Assert.Equal(2, convosResult.Conversations.Count);
        }
Exemple #6
0
        public static async Task <bool> DoExport()
        {
            // REPLACE with REAL APPID and PASSWORD
            var           credentials       = new MicrosoftAppCredentials("MsAppId", "MsAppPassword");
            StringBuilder outputMessage     = new StringBuilder();
            string        continuationToken = "";

            // REPLACE with bot framework API
            var stateUrl = new Uri("https://intercom-api-scratch.azurewebsites.net");

            MicrosoftAppCredentials.TrustServiceUrl(stateUrl.AbsoluteUri);


            var client = new StateClient(stateUrl, credentials);
            var state  = client.BotState;
            BotStateDataResult stateResult = null;

            do
            {
                try
                {
                    // should work with "directline", "facebook", or "kik"
                    stateResult = await BotStateExtensions.ExportBotStateDataAsync(state, "directline", continuationToken).ConfigureAwait(false);

                    foreach (var datum in stateResult.BotStateData)
                    {
                        outputMessage.Append($"conversationID: {datum.ConversationId}\tuserId: {datum.UserId}\tdata:{datum.Data}\n");
                        // If you were exporting into a new bot state store, here is where you would write the data
                        //if (string.IsNullOrEmpty(datum.ConversationId))
                        //{
                        //    // use SetUserData(datum.UserId, data.Data);
                        //}
                        //else
                        //{
                        //    SetPrivateConversationData(datum.UserId, datum.ConversationId, datum.Data);
                        //}
                    }
                    continuationToken = stateResult.ContinuationToken;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            } while (!string.IsNullOrEmpty(continuationToken));

            Console.WriteLine(outputMessage.ToString());


            continuationToken = null;
            outputMessage     = new StringBuilder();
            // REPLACE with channel's URL.
            var connectionsUrl = new Uri("http://ic-directline-scratch.azurewebsites.net");

            MicrosoftAppCredentials.TrustServiceUrl(connectionsUrl.AbsoluteUri);
            var connectorClient = new ConnectorClient(connectionsUrl, credentials);
            var conversations   = connectorClient.Conversations;
            ConversationsResult conversationResults = null;

            do
            {
                try
                {
                    conversationResults = await conversations.GetConversationsAsync(continuationToken).ConfigureAwait(false);

                    if (conversationResults == null)
                    {
                        outputMessage.Append("Internal error, conversation results was empty");
                    }
                    else if (conversationResults.Conversations == null)
                    {
                        outputMessage.Append("No conversations found for this bot in this channel");
                    }
                    else
                    {
                        outputMessage.Append($"Here is a batch of {conversationResults.Conversations.Count} conversations:\n");
                        foreach (var conversationMembers in conversationResults.Conversations)
                        {
                            string members = string.Join(", ",
                                                         conversationMembers.Members.Select(member => member.Id));
                            outputMessage.Append($"Conversation: {conversationMembers.Id} members: {members}\n");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                continuationToken = conversationResults?.Skip;  // should be ContinuationToken (this version is built on an old library
            } while (!string.IsNullOrEmpty(continuationToken));
            Console.WriteLine(outputMessage.ToString());

            return(true);
        }