ConversationReferenceEx.cs
1 using System;
2 
3 namespace Microsoft.Bot.Connector
4 {
5  public partial class ConversationReference : IEquatable<ConversationReference>
6  {
11  {
12  return new Activity
13  {
14  Type = ActivityTypes.Message,
15  Id = Guid.NewGuid().ToString(),
16  Recipient = new ChannelAccount
17  {
18  Id = this.Bot.Id,
19  Name = this.Bot.Name
20  },
21  ChannelId = this.ChannelId,
22  ServiceUrl = this.ServiceUrl,
23  Conversation = new ConversationAccount
24  {
25  Id = this.Conversation.Id,
26  IsGroup = this.Conversation.IsGroup,
27  Name = this.Conversation.Name
28  },
29  From = new ChannelAccount
30  {
31  Id = this.User.Id,
32  Name = this.User.Id
33  }
34  };
35  }
36 
41  {
42  var msg = this.GetPostToBotMessage();
43 
44  // swap from and recipient
45  var bot = msg.Recipient;
46  var user = msg.From;
47  msg.From = bot;
48  msg.Recipient = user;
49 
50  return msg;
51  }
52 
53  public bool Equals(ConversationReference other)
54  {
55  return other != null
56  && object.Equals(this.User, other.User)
57  && object.Equals(this.Bot, other.Bot)
58  && object.Equals(this.Conversation, other.Conversation)
59  && this.ChannelId == other.ChannelId
60  && this.ServiceUrl == other.ServiceUrl;
61  }
62 
63  public override bool Equals(object other)
64  {
65  return this.Equals(other as ConversationReference);
66  }
67 
68  public override int GetHashCode()
69  {
70  var code = this.User.GetHashCode()
71  ^ this.Bot.GetHashCode()
72  ^ this.Conversation.GetHashCode()
73  ^ this.ServiceUrl.GetHashCode()
74  ^ this.ChannelId.GetHashCode();
75  return code;
76  }
77  }
78 }
Channel account information for a conversation
string Id
Channel id for the user or bot on this channel (Example: joe@smith.com, or or 123456) ...
const string Message
Message from a user -> bot or bot -> User
Activity GetPostToBotMessage()
Creates Activity from conversation reference as it is posted to bot.
An object relating to a particular point in a conversation
An Activity is the basic communication type for the Bot Framework 3.0 protocol
Definition: ActivityEx.cs:18
Activity GetPostToUserMessage()
Creates Activity from conversation reference that can be posted to user as reply. ...
string Id
Channel id for the user or bot on this channel (Example: joe@smith.com, or or 123456) ...
Channel account information needed to route a message