/// <summary> /// Initializes a new instance of the ConversationParameters class. /// </summary> public ConversationParameters(ChannelAccount bot = default(ChannelAccount), bool? isGroup = default(bool?), IList<ChannelAccount> members = default(IList<ChannelAccount>), string topicName = default(string)) { Bot = bot; IsGroup = isGroup; Members = members; TopicName = topicName; }
public async Task SendBotMessage(string messageText, BotUserDataDto botUserDataDto) { MicrosoftAppCredentials.TrustServiceUrl("https://smba.trafficmanager.net/apis"); var conversationId = botUserDataDto.UserConversationId; var userAccount = new Microsoft.Bot.Connector.ChannelAccount(botUserDataDto.UserConversationId, botUserDataDto.UserName); var botAccount = new Microsoft.Bot.Connector.ChannelAccount(botUserDataDto.BotConversationId, botUserDataDto.BotName); var connector = new ConnectorClient(new Uri("https://smba.trafficmanager.net/apis"), "[KEY]", "[KEY]"); // Create a new message. Microsoft.Bot.Connector.IMessageActivity message = Activity.CreateMessageActivity(); if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(botUserDataDto.ChannelId)) { // If conversation ID and channel ID was stored previously, use it. message.ChannelId = "skype"; } else { // Conversation ID was not stored previously, so create a conversation. // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window. conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id; } // Set the address-related properties in the message and send the message. message.From = botAccount; message.Recipient = userAccount; message.Conversation = new ConversationAccount(id: conversationId); message.Text = messageText; message.Locale = "es-us"; await connector.Conversations.SendToConversationAsync((Activity)message); }
private async Task <Microsoft.Bot.Connector.DirectLine.Activity> PostToAgentBotAsync2(Microsoft.Bot.Connector.DirectLine.Activity activityFromUser) { var directLineSecret = Configuration.ConfigurationHelper.GetString("AgentBot_DirectLine_Secret"); var agentStatusDB = Configuration.ConfigurationHelper.GetString("BotStatusDBConnectionString"); var agentStorage = new AgentStatusStorage(agentStatusDB); var agent = await agentStorage.QueryAgentStatusAsync(activityFromUser.Recipient.Id); using (var client = new ConnectorClient(new Uri("https://smba.trafficmanager.net/apis"))) { var recipient = new Microsoft.Bot.Connector.ChannelAccount(/*agent.AgentIdInChannel*/ "29:1Gk7vrlkdaMoN6fCtrycxkJfHcPS8zvi49Gukq4XuZAo"); var from = new Microsoft.Bot.Connector.ChannelAccount(""); //var conversatoin = await client.Conversations.CreateDirectConversationAsync(from, recipient); var message = new Microsoft.Bot.Connector.Activity { Text = activityFromUser.Text, From = from, Conversation = new Microsoft.Bot.Connector.ConversationAccount { Id = agent.ConversationId }, Recipient = recipient }; var response = await client.Conversations.SendToConversationAsync(message); return(null); } }
/// <summary> /// Initializes a new instance of the Activity class. /// </summary> public Activity(string type = default(string), string id = default(string), DateTime? timestamp = default(DateTime?), string serviceUrl = default(string), string channelId = default(string), ChannelAccount from = default(ChannelAccount), ConversationAccount conversation = default(ConversationAccount), ChannelAccount recipient = default(ChannelAccount), string textFormat = default(string), string attachmentLayout = default(string), IList<ChannelAccount> membersAdded = default(IList<ChannelAccount>), IList<ChannelAccount> membersRemoved = default(IList<ChannelAccount>), string topicName = default(string), bool? historyDisclosed = default(bool?), string locale = default(string), string text = default(string), string summary = default(string), IList<Attachment> attachments = default(IList<Attachment>), IList<Entity> entities = default(IList<Entity>), object channelData = default(object), string action = default(string), string replyToId = default(string)) { Type = GetActivityType(type); Id = id; Timestamp = timestamp; ServiceUrl = serviceUrl; ChannelId = channelId; From = from; Conversation = conversation; Recipient = recipient; TextFormat = textFormat; AttachmentLayout = attachmentLayout; MembersAdded = membersAdded; MembersRemoved = membersRemoved; TopicName = topicName; HistoryDisclosed = historyDisclosed; Locale = locale; Text = text; Summary = summary; Attachments = attachments; Entities = entities; ChannelData = channelData; Action = action; ReplyToId = replyToId; }
/// <summary> /// Initializes a new instance of the ConversationParameters class. /// </summary> /// <param name="isGroup">IsGroup</param> /// <param name="bot">The bot address for this conversation</param> /// <param name="members">Members to add to the conversation</param> /// <param name="topicName">(Optional) Topic of the conversation (if /// supported by the channel)</param> /// <param name="activity">(Optional) When creating a new conversation, /// use this activity as the initial message to the /// conversation</param> /// <param name="channelData">Channel specific payload for creating the /// conversation</param> public ConversationParameters(bool?isGroup = default(bool?), ChannelAccount bot = default(ChannelAccount), IList <ChannelAccount> members = default(IList <ChannelAccount>), string topicName = default(string), Activity activity = default(Activity), object channelData = default(object)) { IsGroup = isGroup; Bot = bot; Members = members; TopicName = topicName; Activity = activity; ChannelData = channelData; CustomInit(); }
/// <summary> /// Initializes a new instance of the Activity class. /// </summary> /// <param name="type">Contains the activity type. Possible values /// include: 'message', 'contactRelationUpdate', 'conversationUpdate', /// 'typing', 'endOfConversation', 'event', 'invoke', 'deleteUserData', /// 'messageUpdate', 'messageDelete', 'installationUpdate', /// 'messageReaction', 'suggestion', 'trace', 'handoff'</param> /// <param name="id">Contains an ID that uniquely identifies the /// activity on the channel.</param> /// <param name="timestamp">Contains the date and time that the message /// was sent, in UTC, expressed in ISO-8601 format.</param> /// <param name="localTimestamp">Contains the local date and time of /// the message, expressed in ISO-8601 format. /// For example, 2016-09-23T13:07:49.4714686-07:00.</param> /// <param name="localTimezone">Contains the name of the local timezone /// of the message, expressed in IANA Time Zone database format. /// For example, America/Los_Angeles.</param> /// <param name="serviceUrl">Contains the URL that specifies the /// channel's service endpoint. Set by the channel.</param> /// <param name="channelId">Contains an ID that uniquely identifies the /// channel. Set by the channel.</param> /// <param name="from">Identifies the sender of the /// message.</param> /// <param name="conversation">Identifies the conversation to which the /// activity belongs.</param> /// <param name="recipient">Identifies the recipient of the /// message.</param> /// <param name="textFormat">Format of text fields Default:markdown. /// Possible values include: 'markdown', 'plain', 'xml'</param> /// <param name="attachmentLayout">The layout hint for multiple /// attachments. Default: list. Possible values include: 'list', /// 'carousel'</param> /// <param name="membersAdded">The collection of members added to the /// conversation.</param> /// <param name="membersRemoved">The collection of members removed from /// the conversation.</param> /// <param name="reactionsAdded">The collection of reactions added to /// the conversation.</param> /// <param name="reactionsRemoved">The collection of reactions removed /// from the conversation.</param> /// <param name="topicName">The updated topic name of the /// conversation.</param> /// <param name="historyDisclosed">Indicates whether the prior history /// of the channel is disclosed.</param> /// <param name="locale">A locale name for the contents of the text /// field. /// The locale name is a combination of an ISO 639 two- or three-letter /// culture code associated with a language /// and an ISO 3166 two-letter subculture code associated with a /// country or region. /// The locale name can also correspond to a valid BCP-47 language /// tag.</param> /// <param name="text">The text content of the message.</param> /// <param name="speak">The text to speak.</param> /// <param name="inputHint">Indicates whether your bot is accepting, /// expecting, or ignoring user input after the message is delivered to /// the client. Possible values include: 'acceptingInput', /// 'ignoringInput', 'expectingInput'</param> /// <param name="summary">The text to display if the channel cannot /// render cards.</param> /// <param name="suggestedActions">The suggested actions for the /// activity.</param> /// <param name="attachments">Attachments</param> /// <param name="entities">Represents the entities that were mentioned /// in the message.</param> /// <param name="channelData">Contains channel-specific /// content.</param> /// <param name="action">Indicates whether the recipient of a /// contactRelationUpdate was added or removed from the sender's /// contact list.</param> /// <param name="replyToId">Contains the ID of the message to which /// this message is a reply.</param> /// <param name="label">A descriptive label for the activity.</param> /// <param name="valueType">The type of the activity's value /// object.</param> /// <param name="value">A value that is associated with the /// activity.</param> /// <param name="name">The name of the operation associated with an /// invoke or event activity.</param> /// <param name="relatesTo">A reference to another conversation or /// activity.</param> /// <param name="code">The a code for endOfConversation activities that /// indicates why the conversation ended. Possible values include: /// 'unknown', 'completedSuccessfully', 'userCancelled', 'botTimedOut', /// 'botIssuedInvalidMessage', 'channelFailed'</param> /// <param name="expiration">The time at which the activity should be /// considered to be "expired" and should not be presented to the /// recipient.</param> /// <param name="importance">The importance of the activity. Possible /// values include: 'low', 'normal', 'high'</param> /// <param name="deliveryMode">A delivery hint to signal to the /// recipient alternate delivery paths for the activity. /// The default delivery mode is "default". Possible values include: /// 'normal', 'notification'</param> /// <param name="listenFor">List of phrases and references that speech /// and language priming systems should listen for</param> /// <param name="textHighlights">The collection of text fragments to /// highlight when the activity contains a ReplyToId value.</param> /// <param name="semanticAction">An optional programmatic action /// accompanying this request</param> /// <param name="callerId">A string containing an IRI identifying the /// caller of a bot. This field is not intended to be transmitted /// over the wire, but is instead populated by bots and clients based on /// cryptographically verifiable data that asserts the identity of /// the callers (e.g. tokens).</param> public Activity(string type = default(string), string id = default(string), System.DateTimeOffset?timestamp = default(System.DateTimeOffset?), System.DateTimeOffset?localTimestamp = default(System.DateTimeOffset?), string serviceUrl = default(string), string channelId = default(string), ChannelAccount from = default(ChannelAccount), ConversationAccount conversation = default(ConversationAccount), ChannelAccount recipient = default(ChannelAccount), string textFormat = default(string), string attachmentLayout = default(string), IList <ChannelAccount> membersAdded = default(IList <ChannelAccount>), IList <ChannelAccount> membersRemoved = default(IList <ChannelAccount>), IList <MessageReaction> reactionsAdded = default(IList <MessageReaction>), IList <MessageReaction> reactionsRemoved = default(IList <MessageReaction>), string topicName = default(string), bool?historyDisclosed = default(bool?), string locale = default(string), string text = default(string), string speak = default(string), string inputHint = default(string), string summary = default(string), SuggestedActions suggestedActions = default(SuggestedActions), IList <Attachment> attachments = default(IList <Attachment>), IList <Entity> entities = default(IList <Entity>), object channelData = default(object), string action = default(string), string replyToId = default(string), string label = default(string), string valueType = default(string), object value = default(object), string name = default(string), ConversationReference relatesTo = default(ConversationReference), string code = default(string), System.DateTimeOffset?expiration = default(System.DateTimeOffset?), string importance = default(string), string deliveryMode = default(string), IList <string> listenFor = default(IList <string>), IList <TextHighlight> textHighlights = default(IList <TextHighlight>), SemanticAction semanticAction = default(SemanticAction), string localTimezone = default(string), string callerId = default(string)) { Type = type; Id = id; Timestamp = timestamp; LocalTimestamp = localTimestamp; LocalTimezone = localTimezone; ServiceUrl = serviceUrl; ChannelId = channelId; From = from; Conversation = conversation; Recipient = recipient; TextFormat = textFormat; AttachmentLayout = attachmentLayout; MembersAdded = membersAdded; MembersRemoved = membersRemoved; ReactionsAdded = reactionsAdded; ReactionsRemoved = reactionsRemoved; TopicName = topicName; HistoryDisclosed = historyDisclosed; Locale = locale; Text = text; Speak = speak; InputHint = inputHint; Summary = summary; SuggestedActions = suggestedActions; Attachments = attachments; Entities = entities; ChannelData = channelData; Action = action; ReplyToId = replyToId; Label = label; ValueType = valueType; Value = value; Name = name; RelatesTo = relatesTo; Code = code; Expiration = expiration; Importance = importance; DeliveryMode = deliveryMode; ListenFor = listenFor; TextHighlights = textHighlights; SemanticAction = semanticAction; CallerId = callerId; CustomInit(); }
/// <summary> /// Create a new direct conversation between a bot and a user /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from</param> /// <param name='user'>User to create conversation with</param> /// <param name='cancellationToken'>The cancellation token.</param> public static async Task <ResourceResponse> CreateDirectConversationAsync(this IConversations operations, ChannelAccount bot, ChannelAccount user, CancellationToken cancellationToken = default(CancellationToken)) { var _result = await operations.CreateConversationWithHttpMessagesAsync(GetDirectParameters(bot, user), null, cancellationToken).ConfigureAwait(false); return(await _result.HandleErrorAsync <ResourceResponse>().ConfigureAwait(false)); }
/// <summary> /// Create a new direct conversation between a bot and a user /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from</param> /// <param name='user'>User to create conversation with</param> public static ResourceResponse CreateDirectConversation(this IConversations operations, ChannelAccount bot, ChannelAccount user) { return(Task.Factory.StartNew(s => ((IConversations)s).CreateConversationAsync(GetDirectParameters(bot, user)), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private static ConversationParameters GetDirectParameters(ChannelAccount bot, ChannelAccount user) { return(new ConversationParameters() { Bot = bot, Members = new ChannelAccount[] { user } }); }
/// <summary> /// Initializes a new instance of the Activity class. /// </summary> public Activity(string type = default(string), string id = default(string), DateTime?timestamp = default(DateTime?), DateTime?localTimestamp = default(DateTime?), string serviceUrl = default(string), string channelId = default(string), ChannelAccount from = default(ChannelAccount), ConversationAccount conversation = default(ConversationAccount), ChannelAccount recipient = default(ChannelAccount), string textFormat = default(string), string attachmentLayout = default(string), IList <ChannelAccount> membersAdded = default(IList <ChannelAccount>), IList <ChannelAccount> membersRemoved = default(IList <ChannelAccount>), string topicName = default(string), bool?historyDisclosed = default(bool?), string locale = default(string), string text = default(string), string summary = default(string), IList <CardAction> suggestedActions = default(IList <CardAction>), IList <Attachment> attachments = default(IList <Attachment>), IList <Entity> entities = default(IList <Entity>), object channelData = default(object), string action = default(string), string replyToId = default(string), object value = default(object), string name = default(string), ConversationReference relatesTo = default(ConversationReference)) { Type = type; Id = id; Timestamp = timestamp; LocalTimestamp = localTimestamp; ServiceUrl = serviceUrl; ChannelId = channelId; From = from; Conversation = conversation; Recipient = recipient; TextFormat = textFormat; AttachmentLayout = attachmentLayout; MembersAdded = membersAdded; MembersRemoved = membersRemoved; TopicName = topicName; HistoryDisclosed = historyDisclosed; Locale = locale; Text = text; Summary = summary; SuggestedActions = suggestedActions; Attachments = attachments; Entities = entities; ChannelData = channelData; Action = action; ReplyToId = replyToId; Value = value; Name = name; RelatesTo = relatesTo; }
/// <summary> /// Initializes a new instance of the ConversationReference class. /// </summary> /// <param name="activityId">(Optional) ID of the activity to refer /// to</param> /// <param name="user">(Optional) User participating in this /// conversation</param> /// <param name="bot">Bot participating in this conversation</param> /// <param name="conversation">Conversation reference</param> /// <param name="channelId">Channel ID</param> /// <param name="serviceUrl">Service endpoint where operations /// concerning the referenced conversation may be performed</param> public ConversationReference(string activityId = default(string), ChannelAccount user = default(ChannelAccount), ChannelAccount bot = default(ChannelAccount), ConversationAccount conversation = default(ConversationAccount), string channelId = default(string), string serviceUrl = default(string)) { ActivityId = activityId; User = user; Bot = bot; Conversation = conversation; ChannelId = channelId; ServiceUrl = serviceUrl; CustomInit(); }
/// <summary> /// Create a new direct conversation between a bot and a user. /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from.</param> /// <param name='user'>User to create conversation with.</param> /// <param name="activity">(OPTIONAL) initial message to send to the new conversation.</param> /// <param name='cancellationToken'>The cancellation token.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public static async Task <ConversationResourceResponse> CreateDirectConversationAsync(this IConversations operations, ChannelAccount bot, ChannelAccount user, Activity activity = null, CancellationToken cancellationToken = default(CancellationToken)) { var result = await operations.CreateConversationWithHttpMessagesAsync(GetDirectParameters(bot, user, activity), null, cancellationToken).ConfigureAwait(false); return(result.Body); }
/// <summary> /// Create a new direct conversation between a bot and a user /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from</param> /// <param name='user'>User to create conversation with</param> /// <param name="activity">(OPTIONAL) initial message to send to the new conversation</param> /// <param name='cancellationToken'>The cancellation token.</param> public static async Task <ConversationResourceResponse> CreateDirectConversationAsync(this IConversations operations, ChannelAccount bot, ChannelAccount user, Activity activity = null, CancellationToken cancellationToken = default(CancellationToken)) { var _result = await operations.CreateConversationWithHttpMessagesAsync(GetDirectParameters(bot, user, activity), null, cancellationToken).ConfigureAwait(false); var res = await _result.HandleErrorAsync <ConversationResourceResponse>().ConfigureAwait(false); MicrosoftAppCredentials.TrustServiceUrl(res.ServiceUrl); return(res); }
/// <summary> /// Create a new direct conversation between a bot and a user /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from</param> /// <param name='user'>User to create conversation with</param> /// <param name='cancellationToken'>The cancellation token.</param> public static async Task<ResourceResponse> CreateDirectConversationAsync(this IConversations operations, ChannelAccount bot, ChannelAccount user, CancellationToken cancellationToken = default(CancellationToken)) { var _result = await operations.CreateConversationWithHttpMessagesAsync(GetDirectParameters(bot, user), null, cancellationToken).ConfigureAwait(false); return _result.HandleError<ResourceResponse>(); }
/// <summary> /// Create a new direct conversation between a bot and a user /// </summary> /// <param name='operations'>The operations group for this extension method.</param> /// <param name='bot'>Bot to create conversation from</param> /// <param name='user'>User to create conversation with</param> public static ResourceResponse CreateDirectConversation(this IConversations operations, ChannelAccount bot, ChannelAccount user) { return Task.Factory.StartNew(s => ((IConversations)s).CreateConversationAsync(GetDirectParameters(bot, user)), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private static ConversationParameters GetDirectParameters(ChannelAccount bot, ChannelAccount user) { return new ConversationParameters() { Bot = bot, Members = new ChannelAccount[] { user } }; }