/// <summary> /// Handles conversational updates. /// </summary> /// <param name="activity">Incoming request from Bot Framework.</param> /// <param name="connectorClient">Connector client instance for posting to Bot Framework.</param> /// <returns>Task tracking operation.</returns> private static async Task HandleConversationUpdates(Activity activity, ConnectorClient connectorClient) { TeamEventBase eventData = activity.GetConversationUpdateData(); switch (eventData.EventType) { case TeamEventType.ChannelCreated: { ChannelCreatedEvent channelCreatedEvent = eventData as ChannelCreatedEvent; Activity newActivity = new Activity { Type = ActivityTypes.Message, ChannelId = "msteams", ServiceUrl = activity.ServiceUrl, From = activity.Recipient, Text = channelCreatedEvent.Channel.Name + " Channel creation complete", ChannelData = new TeamsChannelData { Channel = channelCreatedEvent.Channel, Team = channelCreatedEvent.Team, Tenant = channelCreatedEvent.Tenant }, }; await connectorClient.Conversations.SendToConversationWithRetriesAsync(newActivity, channelCreatedEvent.Channel.Id); break; } case TeamEventType.ChannelDeleted: { ChannelDeletedEvent channelDeletedEvent = eventData as ChannelDeletedEvent; Activity newActivity = activity.CreateReplyToGeneralChannel(channelDeletedEvent.Channel.Name + " Channel deletion complete"); await connectorClient.Conversations.SendToConversationWithRetriesAsync(newActivity, activity.GetGeneralChannel().Id); break; } case TeamEventType.MembersAdded: { MembersAddedEvent memberAddedEvent = eventData as MembersAddedEvent; Activity newActivity = activity.CreateReplyToGeneralChannel("Members added to team."); await connectorClient.Conversations.SendToConversationWithRetriesAsync(newActivity, activity.GetGeneralChannel().Id); break; } case TeamEventType.MembersRemoved: { MembersRemovedEvent memberRemovedEvent = eventData as MembersRemovedEvent; Activity newActivity = activity.CreateReplyToGeneralChannel("Members removed from the team."); await connectorClient.Conversations.SendToConversationWithRetriesAsync(newActivity, activity.GetGeneralChannel().Id); break; } } }
public void Handle(ChannelCreatedEvent e) { this.Name = e.Name; this.Alias = e.Alias; this.ConnectArea = e.ConnectArea; this.Default = e.Default; this.CreateDate = e.Timestamp; }
public Channel(Guid id, string name) { var e = new ChannelCreatedEvent { ID = id, Name = name, TimeStamp = DateTime.UtcNow }; ApplyEvent(e); }
/// <summary> /// Handles the channel created event asynchronous. /// </summary> /// <param name="channelCreatedEvent">The channel created event.</param> /// <returns>Task tracking operation.</returns> public async Task HandleChannelCreatedEventAsync(ChannelCreatedEvent channelCreatedEvent) { TeamOperationHistory conversationHistory = await this.teamHistoryAccessor.AuditLog.GetAsync(channelCreatedEvent.TurnContext, () => new TeamOperationHistory()).ConfigureAwait(false); if (conversationHistory.MemberOperations == null) { conversationHistory.MemberOperations = new List <OperationDetails>(); } conversationHistory.MemberOperations.Add(new OperationDetails { ObjectId = channelCreatedEvent.Channel.Id, Operation = "ChannelCreated", OperationTime = DateTimeOffset.Now, }); await this.teamHistoryAccessor.AuditLog.SetAsync(channelCreatedEvent.TurnContext, conversationHistory).ConfigureAwait(false); await this.teamHistoryAccessor.ConversationState.SaveChangesAsync(channelCreatedEvent.TurnContext).ConfigureAwait(false); }
public void OnChatPacket(PacketReader reader) { int messageNum = reader.ReadInt16(); reader.ReadString(4); // Language byte[] packet = reader.GetData(); switch (messageNum) { case 0x25: { int messageType = reader.ReadInt16(); string username = reader.ReadUnicodeString(); string message = reader.ReadUnicodeString(); Match matches = Regex.Match(message, "{(.*)}\\s+(.*)"); if (matches.Success) { string channel = matches.Groups[1].Value; string text = matches.Groups[2].Value; Messages.Add(new ChatMessage { Username = username, Channel = channel, Text = text }); ChatMessageEvent?.Invoke(username, channel, text); } break; } case 0x3e8: { string channel = reader.ReadUnicodeString(); if (!Channels.Contains(channel)) { Channels.Add(channel); ChannelCreatedEvent?.Invoke(channel); } break; } case 0x3e9: { string channel = reader.ReadUnicodeString(); if (Channels.Contains(channel)) { Channels.Remove(channel); ChannelRemovedEvent?.Invoke(channel); } break; } case 0x3ee: { reader.ReadInt16(); string userName = reader.ReadUnicodeString(); if (!Users.Contains(userName)) { Users.Add(userName); UserJoinedEvent?.Invoke(userName, string.Empty); } break; } case 0x3ef: { string userName = reader.ReadUnicodeString(); if (Users.Contains(userName)) { Users.Remove(userName); UserLeftEvent?.Invoke(userName, string.Empty); } break; } case 0x3f1: { CurrentChannel = reader.ReadUnicodeString(); JoinedChatChannelEvent?.Invoke(CurrentChannel); break; } case 0x3f0: { Users.Clear(); ClearUsersEvent?.Invoke(); break; } case 0x3f4: { LeftChatChannelEvent?.Invoke(CurrentChannel); CurrentChannel = null; break; } // ReSharper disable once RedundantEmptySwitchSection default: break; } }
protected void OnChannelCreated(ChannelCreatedEvent e) { _id = e.ID; _name = e.Name; _timestamp = e.TimeStamp; }