Exemplo n.º 1
0
        /// <summary>
        /// Send a mesage.
        /// </summary>
        /// <param name="conversations">The <see cref="IConversations"/> instance</param>
        /// <param name="conversationId">Thread id where the message will be sent</param>
        /// <param name="text">Message text</param>
        /// <param name="entities">Entities to attach to the message</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation</returns>
        public static Task <ResourceResponse> SendMessageAsync(this IConversations conversations, string conversationId, string text, List <Entity> entities = null)
        {
            var activity = new Activity(ActivityTypes.Message)
            {
                Conversation = new ConversationAccount {
                    Id = conversationId
                },
                Text     = text,
                Entities = entities,
            };

            return(conversations.SendToConversationWithRetriesAsync(activity));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send attachments in list format.
        /// </summary>
        /// <param name="conversations">The <see cref="IConversations"/> instance</param>
        /// <param name="conversationId">Thread id where the message will be sent</param>
        /// <param name="attachments">Attachments</param>
        /// <param name="text">Message text</param>
        /// <param name="summary">Message summary</param>
        /// <param name="entities">Entities to attach to the message</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation</returns>
        public static Task SendCardListAsync(this IConversations conversations, string conversationId, List <Attachment> attachments, string text = null, string summary = null, List <Entity> entities = null)
        {
            var activity = new Activity(ActivityTypes.Message)
            {
                Conversation = new ConversationAccount {
                    Id = conversationId
                },
                AttachmentLayout = AttachmentLayoutTypes.List,
                Text             = text,
                Summary          = summary,
                Attachments      = attachments,
                Entities         = entities,
            };

            return(conversations.SendToConversationWithRetriesAsync(activity));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send an attachment.
        /// </summary>
        /// <param name="conversations">The <see cref="IConversations"/> instance</param>
        /// <param name="conversationId">Thread id where the message will be sent</param>
        /// <param name="attachment">Attachment to send</param>
        /// <param name="text">Message text</param>
        /// <param name="summary">Message summary</param>
        /// <param name="entities">Entities to attach to the message</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation</returns>
        public static Task <ResourceResponse> SendCardAsync(this IConversations conversations, string conversationId, Attachment attachment, string text = null, string summary = null, List <Entity> entities = null)
        {
            var activity = new Activity(ActivityTypes.Message)
            {
                Conversation = new ConversationAccount {
                    Id = conversationId
                },
                Text        = text,
                Summary     = summary,
                Attachments = new List <Attachment> {
                    attachment
                },
                Entities = entities,
            };

            return(conversations.SendToConversationWithRetriesAsync(activity));
        }
Exemplo n.º 4
0
        private async Task <ResourceResponse> SendAsyncWorker(IConversations conversations)
        {
            // Create conversation if needed
            if (this.Activity.Conversation?.Id == null)
            {
                var conversationId = await conversations.CreateOrGetDirectConversationAsync(this.TenantId, this.Activity.Recipient.Id);

                this.Activity.Conversation = new ConversationAccount {
                    Id = conversationId
                };
            }

            // Is this activity going to split? If so, send it as a reply chain
            if ((this.MessageType == MessageType.Event) && this.IsActivitySubjectToSplitting(this.Activity))
            {
                // Create the reply chain
                var rootMessage = new Activity(ActivityTypes.Message)
                {
                    Text     = this.Activity.Text,
                    Entities = this.Activity.Entities,
                };
                var conversationResource = await conversations.CreateReplyChainAsync(this.Activity.Conversation.Id, rootMessage);

                // Post the cards as a messages in the reply chain
                ResourceResponse response = null;
                foreach (var attachment in this.Activity.Attachments)
                {
                    response = await conversations.SendCardAsync(conversationResource.Id, attachment);
                }

                // There's no single resource that can be returned, so just return the last one
                return(response);
            }
            else
            {
                return(await conversations.SendToConversationWithRetriesAsync(this.Activity));
            }
        }