/// <summary> /// Creates or gets direct conversation between a bot and user. /// </summary> /// <param name="conversationClient">Conversation client instance.</param> /// <param name="bot">Bot account.</param> /// <param name="user">User to create conversation with.</param> /// <param name="tenantId">TenantId of the user.</param> /// <returns>Conversation creation or get response.</returns> public static ConversationResourceResponse CreateOrGetDirectConversation( this IConversations conversationClient, ChannelAccount bot, ChannelAccount user, string tenantId) { return(conversationClient.CreateConversationAsync(new ConversationParameters() { Bot = bot, ChannelData = JObject.FromObject( new TeamsChannelData { Tenant = new TenantInfo { Id = tenantId } }, JsonSerializer.Create(new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore })), Members = new List <ChannelAccount>() { user } }).Result); }
/// <summary> /// Starts a reply chain in the given channel. /// </summary> /// <param name="conversations">The <see cref="IConversations"/> instance</param> /// <param name="channelId">Channel to post to</param> /// <param name="activity">Activity to use as root post</param> /// <returns>Conversation resource</returns> public static Task <ConversationResourceResponse> CreateReplyChainAsync(this IConversations conversations, string channelId, Activity activity) { var parameters = new ConversationParameters { Activity = activity, ChannelData = new TeamsChannelData { Channel = new ChannelInfo { Id = channelId } }, }; return(conversations.CreateConversationAsync(parameters)); }
/// <summary> /// Creates a conversation between the user and the bot. /// </summary> /// <param name="conversations">The <see cref="IConversations"/> instance</param> /// <param name="tenantId">Tenant Id</param> /// <param name="userTeamsId">teamsId of user</param> /// <returns>conversationId.</returns> public static async Task <string> CreateOrGetDirectConversationAsync(this IConversations conversations, string tenantId, string userTeamsId) { var parameters = new ConversationParameters { Members = new List <ChannelAccount> { new ChannelAccount { Id = userTeamsId } }, ChannelData = new TeamsChannelData { Tenant = new TenantInfo { Id = tenantId } }, }; var result = await conversations.CreateConversationAsync(parameters); return(result.Id); }
public static async Task <ConversationResourceResponse> CreateTeamsThreadAsync( this IConversations conversations, string conversationId, Activity activity, CancellationToken cancellationToken = default(CancellationToken)) { var channelData = activity.GetChannelData <TeamsChannelData>(); var parameters = new ConversationParameters { ChannelData = new TeamsChannelData { Channel = channelData.Channel, Team = channelData.Team, Tenant = channelData.Tenant, }, Activity = activity, }; return(await conversations.CreateConversationAsync(parameters, cancellationToken)); }
// Create Conversaion // POST "v3/conversations" public static ConversationResourceResponse CreateConversation(this IConversations operations, ConversationParameters parameters, Dictionary <string, List <string> > customHeaders) { return(operations.CreateConversationAsync(parameters, customHeaders).GetAwaiter().GetResult()); }
/// <summary> /// CreateConversation /// </summary> /// <remarks> /// Create a new Conversation. /// /// POST to this method with a /// * Bot being the bot creating the conversation /// * IsGroup set to true if this is not a direct message (default is false) /// * Members array contining the members you want to have be in the /// conversation. /// /// The return value is a ResourceResponse which contains a conversation id /// which is suitable for use /// in the message payload and REST API uris. /// /// Most channels only support the semantics of bots initiating a direct /// message conversation. An example of how to do that would be: /// /// ``` /// var resource = await connector.conversations.CreateConversation(new /// ConversationParameters(){ Bot = bot, members = new ChannelAccount[] { new /// ChannelAccount("user1") } ); /// await connect.Conversations.SendToConversationAsync(resource.Id, new /// Activity() ... ) ; /// /// ``` /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Parameters to create the conversation from /// </param> public static ConversationResourceResponse CreateConversation(this IConversations operations, ConversationParameters parameters) { return(operations.CreateConversationAsync(parameters).GetAwaiter().GetResult()); }