Skip to content

Commit

Permalink
Merge pull request #20 from Microsoft/tomlm/newswagger
Browse files Browse the repository at this point in the history
update connector api with new interface definitions
  • Loading branch information
Tom Laird-McConnell authored Jan 24, 2018
2 parents c3183d2 + f55d745 commit 762e721
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 61 deletions.
51 changes: 39 additions & 12 deletions libraries/Microsoft.Bot.Connector/ActivityEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public partial class Activity :
IContactRelationUpdateActivity,
IInstallationUpdateActivity,
IMessageActivity,
IMessageUpdateActivity,
IMessageDeleteActivity,
IMessageReactionActivity,
ISuggestionActivity,
ITypingActivity,
IEndOfConversationActivity,
IEventActivity,
Expand Down Expand Up @@ -72,7 +76,6 @@ public Activity CreateReply(string text = null, string locale = null)
[JsonExtensionData(ReadData = true, WriteData = true)]
public JObject Properties { get; set; } = new JObject();


/// <summary>
/// Create an instance of the Activity class with IMessageActivity masking
/// </summary>
Expand Down Expand Up @@ -158,6 +161,30 @@ public Activity CreateReply(string text = null, string locale = null)
/// </summary>
public IInvokeActivity AsInvokeActivity() { return IsActivity(ActivityTypes.Invoke) ? this : null; }

/// <summary>
/// Return an IMessageUpdateAcitvity if this is a MessageUpdate activity
/// </summary>
/// <returns></returns>
public IMessageUpdateActivity AsMessageUpdateActivity() { return IsActivity(ActivityTypes.MessageUpdate) ? this : null; }

/// <summary>
/// Return an IMessageDeleteActivity if this is a MessageDelete activity
/// </summary>
/// <returns></returns>
public IMessageDeleteActivity AsMessageDeleteActivity() { return IsActivity(ActivityTypes.MessageDelete) ? this : null; }

/// <summary>
/// Return an IMessageReactionActivity if this is a MessageReaction activity
/// </summary>
/// <returns></returns>
public IMessageReactionActivity AsMessageReactionActivity() { return IsActivity(ActivityTypes.MessageReaction) ? this : null; }

/// <summary>
/// Return an ISuggestionActivity if this is a Suggestion activity
/// </summary>
/// <returns></returns>
public ISuggestionActivity AsSuggestionActivity() { return IsActivity(ActivityTypes.Suggestion) ? this : null; }

/// <summary>
/// Maps type to activity types
/// </summary>
Expand Down Expand Up @@ -216,24 +243,20 @@ public Mention[] GetMentions()
return this.Entities?.Where(entity => String.Compare(entity.Type, "mention", ignoreCase: true) == 0)
.Select(e => e.Properties.ToObject<Mention>()).ToArray() ?? new Mention[0];
}
}

public static class ActivityExtensions
{
/// <summary>
/// Get channeldata as typed structure
/// </summary>
/// <param name="activity"></param>
/// <typeparam name="TypeT">type to use</typeparam>
/// <returns>typed object or default(TypeT)</returns>
public static TypeT GetChannelData<TypeT>(this IActivity activity)
public TypeT GetChannelData<TypeT>()
{
if (activity.ChannelData == null)
if (this.ChannelData == null)
return default(TypeT);
return ((JObject)activity.ChannelData).ToObject<TypeT>();
return ((JObject)this.ChannelData).ToObject<TypeT>();
}


/// <summary>
/// Get channeldata as typed structure
/// </summary>
Expand All @@ -243,19 +266,18 @@ public static TypeT GetChannelData<TypeT>(this IActivity activity)
/// <returns>
/// <c>true</c> if value of <seealso cref="IActivity.ChannelData"/> was coerceable to <typeparamref name="TypeT"/>, <c>false</c> otherwise.
/// </returns>
public static bool TryGetChannelData<TypeT>(this IActivity activity,
out TypeT instance)
public bool TryGetChannelData<TypeT>(out TypeT instance)
{
instance = default(TypeT);

try
{
if (activity.ChannelData == null)
if (this.ChannelData == null)
{
return false;
}

instance = GetChannelData<TypeT>(activity);
instance = this.GetChannelData<TypeT>();
return true;
}
catch
Expand All @@ -264,6 +286,11 @@ public static bool TryGetChannelData<TypeT>(this IActivity activity,
}
}

}

public static class ActivityExtensions
{

/// <summary>
/// Is there a mention of Id in the Text Property
/// </summary>
Expand Down
23 changes: 16 additions & 7 deletions libraries/Microsoft.Bot.Connector/ActivityTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Bot.Connector
/// <summary>
/// Types of Activities
/// </summary>
public static class ActivityTypes
public class ActivityTypes
{
/// <summary>
/// Message from a user -> bot or bot -> User
Expand Down Expand Up @@ -40,12 +40,6 @@ public static class ActivityTypes
/// </summary>
public const string EndOfConversation = "endOfConversation";

/// <summary>
/// NOTE: Trigger activity has been renamed to Event activity
/// </summary>
[Obsolete]
public const string Trigger = "trigger";

/// <summary>
/// Asynchronous external event
/// </summary>
Expand All @@ -61,6 +55,16 @@ public static class ActivityTypes
/// </summary>
public const string DeleteUserData = "deleteUserData";

/// <summary>
/// An update to an existing Message Activity
/// </summary>
public const string MessageUpdate = "messageUpdate";

/// <summary>
/// Indicates a delete of an existing Message Activity
/// </summary>
public const string MessageDelete = "messageDelete";

/// <summary>
/// Bot added or removed from channel
/// </summary>
Expand All @@ -70,5 +74,10 @@ public static class ActivityTypes
/// Reaction added or removed from activity
/// </summary>
public const string MessageReaction = "messageReaction";

/// <summary>
/// Suggestion activity - private message
/// </summary>
public const string Suggestion = "suggestion";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ public Activity()
/// activity</param>
/// <param name="code">Code indicating why the conversation has
/// ended</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), object value = default(object), string name = default(string), ConversationReference relatesTo = default(ConversationReference), string code = default(string))
/// <param name="expiration">DateTime to expire the activity as ISO
/// 8601 encoded datetime</param>
/// <param name="importance">Importance of this activity
/// {Low|Normal|High}, null value indicates Normal importance see
/// ActivityImportance)</param>
/// <param name="deliveryMode">Hint to describe how this activity
/// should be delivered.
/// Currently: null or "Default" = default delivery
/// "Notification" = notification semantics</param>
/// <param name="textHighlights">TextHighlight in the activity
/// represented in the ReplyToId property</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), 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<TextHighlight> textHighlights = default(IList<TextHighlight>))
{
Type = type;
Id = id;
Expand Down Expand Up @@ -117,6 +128,10 @@ public Activity()
Name = name;
RelatesTo = relatesTo;
Code = code;
Expiration = expiration;
Importance = importance;
DeliveryMode = deliveryMode;
TextHighlights = textHighlights;
CustomInit();
}

Expand Down Expand Up @@ -327,5 +342,36 @@ public Activity()
[JsonProperty(PropertyName = "code")]
public string Code { get; set; }

/// <summary>
/// Gets or sets dateTime to expire the activity as ISO 8601 encoded
/// datetime
/// </summary>
[JsonProperty(PropertyName = "expiration")]
public System.DateTimeOffset? Expiration { get; set; }

/// <summary>
/// Gets or sets importance of this activity
/// {Low|Normal|High}, null value indicates Normal importance see
/// ActivityImportance)
/// </summary>
[JsonProperty(PropertyName = "importance")]
public string Importance { get; set; }

/// <summary>
/// Gets or sets hint to describe how this activity should be
/// delivered.
/// Currently: null or "Default" = default delivery
/// "Notification" = notification semantics
/// </summary>
[JsonProperty(PropertyName = "deliveryMode")]
public string DeliveryMode { get; set; }

/// <summary>
/// Gets or sets textHighlight in the activity represented in the
/// ReplyToId property
/// </summary>
[JsonProperty(PropertyName = "textHighlights")]
public IList<TextHighlight> TextHighlights { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// <auto-generated>
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace Microsoft.Bot.Connector
{
using Newtonsoft.Json;
using System.Linq;

public partial class TextHighlight
{
/// <summary>
/// Initializes a new instance of the TextHighlight class.
/// </summary>
public TextHighlight()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the TextHighlight class.
/// </summary>
/// <param name="text">plain text fragment to highlight</param>
/// <param name="occurence">index of occurence of the Text (Starting at
/// 1)</param>
public TextHighlight(string text = default(string), int? occurence = default(int?))
{
Text = text;
Occurence = occurence;
CustomInit();
}

/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();

/// <summary>
/// Gets or sets plain text fragment to highlight
/// </summary>
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }

/// <summary>
/// Gets or sets index of occurence of the Text (Starting at 1)
/// </summary>
[JsonProperty(PropertyName = "occurence")]
public int? Occurence { get; set; }

}
}
Loading

0 comments on commit 762e721

Please sign in to comment.