Beispiel #1
0
        public void ConversationAccountInits()
        {
            var isGroup          = true;
            var conversationType = "convoType";
            var id          = "myId";
            var name        = "name";
            var aadObjectId = "aadObjectId";
            var role        = "role";
            var tenantId    = "tenantId";
            var props       = new JObject();

            var convoAccount = new ConversationAccount(isGroup, conversationType, id, name, aadObjectId, role, tenantId)
            {
                Properties = props
            };

            Assert.NotNull(convoAccount);
            Assert.IsType <ConversationAccount>(convoAccount);
            Assert.Equal(isGroup, convoAccount.IsGroup);
            Assert.Equal(conversationType, convoAccount.ConversationType);
            Assert.Equal(id, convoAccount.Id);
            Assert.Equal(name, convoAccount.Name);
            Assert.Equal(aadObjectId, convoAccount.AadObjectId);
            Assert.Equal(role, convoAccount.Role);
            Assert.Equal(tenantId, convoAccount.TenantId);
            Assert.Equal(props, convoAccount.Properties);
        }
        public static IList <Party> CreateParties(
            uint numberOfPartiesToCreate, bool addChannelAccount)
        {
            IList <Party> parties = new List <Party>();

            for (uint i = 0; i < numberOfPartiesToCreate; ++i)
            {
                Counter++;

                ChannelAccount channelAccount = null;

                if (addChannelAccount)
                {
                    channelAccount = new ChannelAccount(
                        $"channelAccountId{Counter}", $"channelAccountName{Counter}");
                }

                ConversationAccount conversationAccount =
                    new ConversationAccount(
                        false,
                        $"conversationAccountId{Counter}",
                        $"conversationAccountName{Counter}");

                parties.Add(new Party(
                                $"serviceUrl{Counter}", $"channelId{Counter}", channelAccount, conversationAccount));
            }

            return(parties);
        }
        /// <summary>
        /// Creates a Bot Framework <see cref="Activity"/> from an HTTP request that contains a Twilio message.
        /// </summary>
        /// <param name="payload">The HTTP request.</param>
        /// <returns>The activity object.</returns>
        public static Activity PayloadToActivity(Dictionary <string, string> payload)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var twilioMessage = JsonConvert.DeserializeObject <TwilioMessage>(JsonConvert.SerializeObject(payload));

            return(new Activity()
            {
                Id = twilioMessage.MessageSid,
                Timestamp = DateTime.UtcNow,
                ChannelId = Channels.Twilio,
                Conversation = new ConversationAccount()
                {
                    Id = twilioMessage.From ?? twilioMessage.Author,
                },
                From = new ChannelAccount()
                {
                    Id = twilioMessage.From ?? twilioMessage.Author,
                },
                Recipient = new ChannelAccount()
                {
                    Id = twilioMessage.To,
                },
                Text = twilioMessage.Body,
                ChannelData = twilioMessage,
                Type = ActivityTypes.Message,
                Attachments = int.TryParse(twilioMessage.NumMedia, out var numMediaResult) && numMediaResult > 0 ? GetMessageAttachments(numMediaResult, payload) : null,
            });
Beispiel #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="serviceUrl">Service URL. Must be provided.</param>
        /// <param name="channelId">Channel ID. Must be provided.</param>
        /// <param name="channelAccount">Channel account (represents a specific user). Can be null
        /// and if so this party is considered to cover everyone in the given channel.
        /// <param name="conversationAccount">Conversation account. Must contain a valid ID.</param>
        public Party(string serviceUrl, string channelId,
                     ChannelAccount channelAccount, ConversationAccount conversationAccount)
        {
            if (string.IsNullOrEmpty(serviceUrl))
            {
                throw new AccessViolationException(nameof(serviceUrl));
            }

            if (string.IsNullOrEmpty(channelId))
            {
                throw new ArgumentException(nameof(channelId));
            }

            if (conversationAccount == null || string.IsNullOrEmpty(conversationAccount.Id))
            {
                throw new ArgumentException(nameof(conversationAccount));
            }

            ServiceUrl          = serviceUrl;
            ChannelId           = channelId;
            ChannelAccount      = channelAccount;
            ConversationAccount = conversationAccount;

            ResetConnectionRequestTime();
            ResetConnectionEstablishedTime();
        }
        public void TeamsParticipantChannelAccountInits()
        {
            var id                = "*****@*****.**";
            var name              = "Joe Smith";
            var givenName         = "Joe";
            var surname           = "Smith";
            var email             = "*****@*****.**";
            var userPrincipalName = "joeUserPrincipalName";
            var tenantId          = "123456-7890-abcd-efgh-ijklmnop";
            var userRole          = "owner";
            var meetingRole       = "owner";
            var inMeeting         = true;
            var conversation      = new ConversationAccount(true);

            var participantAccount = new TeamsParticipantChannelAccount(id, name, givenName, surname, email, userPrincipalName, tenantId, userRole, meetingRole, inMeeting, conversation);

            Assert.NotNull(participantAccount);
            Assert.IsType <TeamsParticipantChannelAccount>(participantAccount);
            Assert.Equal(id, participantAccount.Id);
            Assert.Equal(name, participantAccount.Name);
            Assert.Equal(givenName, participantAccount.GivenName);
            Assert.Equal(surname, participantAccount.Surname);
            Assert.Equal(email, participantAccount.Email);
            Assert.Equal(userPrincipalName, participantAccount.UserPrincipalName);
            Assert.Equal(tenantId, participantAccount.TenantId);
            Assert.Equal(userRole, participantAccount.UserRole);
            Assert.Equal(meetingRole, participantAccount.MeetingRole);
            Assert.Equal(inMeeting, participantAccount.InMeeting);
            Assert.Equal(conversation, participantAccount.Conversation);
        }
Beispiel #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PartyWithTimestamps(string serviceUrl, string channelId,
                            ChannelAccount channelAccount, ConversationAccount conversationAccount)
     : base(serviceUrl, channelId, channelAccount, conversationAccount)
 {
     ResetConnectionRequestTime();
     ResetConnectionEstablishedTime();
 }
Beispiel #7
0
        void OnHubCallBack(string who, string message, string conId)
        {
            var connector = new ConnectorClient(new Uri(serviceUrl));

            var conversation = new ConversationAccount(true, conversationId);
            var botAccount   = new ChannelAccount(botId, botName);

            IMessageActivity replyMessage = Activity.CreateMessageActivity();

            replyMessage.From         = botAccount;
            replyMessage.Conversation = conversation;
            replyMessage.ChannelId    = channelId;
            replyMessage.Recipient    = new ChannelAccount(recipientId, recipientName);
            replyMessage.Text         = message;
            connector.Conversations.SendToConversation((Activity)replyMessage);
            //var myConnector = new ConnectorClient(new Uri(serviceUrl));
            //IMessageActivity newMessage = Activity.CreateMessageActivity();
            //newMessage.Type = ActivityTypes.Message;
            //newMessage.From = botAccount;
            //newMessage.Conversation = conversation;
            //newMessage.Recipient = new ChannelAccount("reply from bo");
            //newMessage.Text = "Yo yo yo!";
            //await connector.Conversations.SendToConversationAsync((Activity)newMessage);


            //var clientConnector = new ConnectorClient(new Uri(serviceUrl));
            //int length = (activity.Text ?? string.Empty).Length;
            //Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
            //await connector.Conversations.ReplyToActivityAsync(reply);
        }
        /// <summary>
        /// Create handoff status event.
        /// </summary>
        /// <param name="conversation">Conversation being handed over.</param>
        /// <param name="state">State, possible values are: "accepted", "failed", "completed".</param>
        /// <param name="message">Additional message for failed handoff.</param>
        /// <returns>handoff event.</returns>
        public static IEventActivity CreateHandoffStatus(ConversationAccount conversation, string state, string message = null)
        {
            if (conversation == null)
            {
                throw new ArgumentNullException(nameof(conversation));
            }

            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            object value;

            if (string.IsNullOrEmpty(message))
            {
                value = new { state };
            }
            else
            {
                value = new { state, message };
            }

            var handoffEvent = CreateHandoffEvent(HandoffEventNames.HandoffStatus, value, conversation);

            return(handoffEvent);
        }
        public static async Task DoWork(IConfiguration configuration, OutgoingMessageQueueData queueData, ILogger log = null)
        {
            //var api = new CosmosInterface(configuration);

            if (string.IsNullOrEmpty(queueData.PhoneNumber) ||
                string.IsNullOrEmpty(queueData.Message))
            {
                return;
            }

            MicrosoftAppCredentials.TrustServiceUrl(configuration.ServiceUrl());
            var creds = new MicrosoftAppCredentials(configuration.MicrosoftAppId(), configuration.MicrosoftAppPassword());
            var credentialProvider = new SimpleCredentialProvider(creds.MicrosoftAppId, creds.MicrosoftAppPassword);
            var adapter            = new BotFrameworkAdapter(credentialProvider);
            var botAccount         = new ChannelAccount()
            {
                Id = configuration.BotPhoneNumber()
            };
            var userAccount = new ChannelAccount()
            {
                Id = PhoneNumber.Standardize(queueData.PhoneNumber)
            };
            var convoAccount = new ConversationAccount(id: userAccount.Id);
            var convo        = new ConversationReference(null, userAccount, botAccount, convoAccount, configuration.ChannelId(), configuration.ServiceUrl());

            await adapter.ContinueConversationAsync(creds.MicrosoftAppId, convo, async (context, token) =>
            {
                await context.SendActivityAsync(queueData.Message);
            }, new CancellationToken());
        }
Beispiel #10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public EngageableParty(string serviceUrl, string channelId,
                        ChannelAccount channelAccount, ConversationAccount conversationAccount)
     : base(serviceUrl, channelId, channelAccount, conversationAccount)
 {
     ResetRequestMadeTime();
     ResetEngagementStartedTime();
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeetingInfo"/> class.
 /// </summary>
 /// <param name="details">The meeting's detailed information.</param>
 /// <param name="conversation">Conversation Account for the meeting.</param>
 /// <param name="organizer">Information specific to this organizer of the specific meeting.</param>
 public MeetingInfo(MeetingDetails details, ConversationAccount conversation = null, TeamsChannelAccount organizer = null)
 {
     Details      = details;
     Conversation = conversation;
     Organizer    = organizer;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TeamsMeetingParticipant"/> class.
 /// </summary>
 /// <param name="user">Teams Channel Account information for this meeting participant.</param>
 /// <param name="conversation">Conversation Account for the meeting.</param>
 /// <param name="meeting">Information specific to this participant in the specific meeting.</param>
 public TeamsMeetingParticipant(TeamsChannelAccount user, ConversationAccount conversation = null, MeetingParticipantInfo meeting = null)
 {
     User         = user;
     Meeting      = meeting;
     Conversation = conversation;
     CustomInit();
 }
        public IList <Activity> GetActivityFromUsersReadMessages(IEnumerable <ChatUserReadStatusModel> usersReadMessages)
        {
            if (usersReadMessages == null)
            {
                return(null);
            }

            ConversationReference selfConversation            = _currentActivity.GetConversationReference();
            ConversationAccount   conversationAccount         = new ConversationAccount(null, null, _currentActivity.Conversation.Id, null, null);
            IList <Activity>      usersReadMessagesActivities = new List <Activity>();

            foreach (ChatUserReadStatusModel userReadMessages in usersReadMessages)
            {
                Activity activityLog = new Activity();
                activityLog.ApplyConversationReference(selfConversation);
                activityLog.ReplyToId      = null;
                activityLog.Text           = string.Empty;
                activityLog.Type           = ActivityTypes.Message;
                activityLog.Conversation   = conversationAccount;
                activityLog.Timestamp      = DateTime.UtcNow;
                activityLog.LocalTimestamp = DateTime.UtcNow;
                activityLog.ChannelData    = CommandFactoryHelper.CreateCommandReadUserMessages(
                    selfConversation.Bot.Id, new CommandReadUserMessages()
                {
                    UserId = userReadMessages.UserId, Date = userReadMessages.Date
                });
                usersReadMessagesActivities.Add(activityLog);
            }

            return(usersReadMessagesActivities);
        }
Beispiel #14
0
        /// <summary>
        /// Tries to establish 1:1 chat between the two given parties.
        /// Note that the conversation owner will have a new separate party in the created engagement.
        /// </summary>
        /// <param name="conversationOwnerParty">The party who owns the conversation (e.g. customer service agent).</param>
        /// <param name="conversationClientParty">The other party in the conversation.</param>
        /// <returns>The result of the operation.</returns>
        public async Task <MessageRouterResult> AddEngagementAsync(
            Party conversationOwnerParty, Party conversationClientParty)
        {
            if (conversationOwnerParty == null || conversationClientParty == null)
            {
                throw new ArgumentNullException(
                          $"Neither of the arguments ({nameof(conversationOwnerParty)}, {nameof(conversationClientParty)}) can be null");
            }

            MessageRouterResult result = new MessageRouterResult()
            {
                ConversationOwnerParty  = conversationOwnerParty,
                ConversationClientParty = conversationClientParty
            };

            Party botParty = RoutingDataManager.FindBotPartyByChannelAndConversation(
                conversationOwnerParty.ChannelId, conversationOwnerParty.ConversationAccount);

            if (botParty != null)
            {
                ConnectorClient connectorClient = new ConnectorClient(new Uri(conversationOwnerParty.ServiceUrl));

                ConversationResourceResponse response =
                    await connectorClient.Conversations.CreateDirectConversationAsync(
                        botParty.ChannelAccount, conversationOwnerParty.ChannelAccount);

                if (response != null && !string.IsNullOrEmpty(response.Id))
                {
                    // The conversation account of the conversation owner for this 1:1 chat is different -
                    // thus, we need to create a new party instance
                    ConversationAccount directConversationAccount = new ConversationAccount(id: response.Id);

                    Party acceptorPartyEngaged = new Party(
                        conversationOwnerParty.ServiceUrl, conversationOwnerParty.ChannelId,
                        conversationOwnerParty.ChannelAccount, directConversationAccount);

                    RoutingDataManager.AddParty(acceptorPartyEngaged);
                    RoutingDataManager.AddParty(
                        new Party(botParty.ServiceUrl, botParty.ChannelId, botParty.ChannelAccount, directConversationAccount), false);

                    result = RoutingDataManager.AddEngagementAndClearPendingRequest(acceptorPartyEngaged, conversationClientParty);
                    result.ConversationResourceResponse = response;
                }
                else
                {
                    result.Type         = MessageRouterResultType.Error;
                    result.ErrorMessage = "Failed to create a direct conversation";
                }
            }
            else
            {
                result.Type         = MessageRouterResultType.Error;
                result.ErrorMessage = "Failed to find the bot instance";
            }

            await HandleAndLogMessageRouterResultAsync(result);

            return(result);
        }
Beispiel #15
0
 public static BotConversationAccount ToBotConversationAccount(this ConversationAccount conversationAccount)
 {
     return(conversationAccount == null
         ? null
         : new BotConversationAccount {
         Id = conversationAccount.Id, Name = conversationAccount.Name, IsGroup = conversationAccount.IsGroup
     });
 }
Beispiel #16
0
        public virtual bool AddParty(string serviceUrl, string channelId,
                                     ChannelAccount channelAccount, ConversationAccount conversationAccount,
                                     bool isUser = true)
        {
            Party newParty = new PartyWithTimestamps(serviceUrl, channelId, channelAccount, conversationAccount);

            return(AddParty(newParty, isUser));
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TeamsParticipantChannelAccount"/> class.
 /// </summary>
 /// <param name="id">Channel id for the user or bot on this channel.
 /// (Example: [email protected], or @joesmith or 123456).</param>
 /// <param name="name">Display friendly name.</param>
 /// <param name="givenName">Given name part of the user name.</param>
 /// <param name="surname">Surname part of the user name.</param>
 /// <param name="email">Email Id of the user.</param>
 /// <param name="userPrincipalName">Unique user principal name.</param>
 /// <param name="tenantId">TenantId of the user.</param>
 /// <param name="userRole">UserRole of the user.</param>
 /// <param name="meetingRole">Role of the participant in the current meeting.</param>
 /// <param name="inMeeting">True, if the participant is in the meeting.</param>
 /// <param name="conversation">Conversation Account for the meeting.</param>
 public TeamsParticipantChannelAccount(string id = default, string name = default, string givenName = default, string surname = default, string email = default, string userPrincipalName = default, string tenantId = default, string userRole = default, string meetingRole = default, bool inMeeting = default, ConversationAccount conversation = null)
     : base(id, name, givenName, surname, email, userPrincipalName, tenantId, userRole)
 {
     MeetingRole  = meetingRole;
     InMeeting    = inMeeting;
     Conversation = conversation;
     CustomInit();
 }
Beispiel #18
0
 internal BotConversation(string serviceUrl, string channelId, ChannelAccount channelAccount, ConversationAccount conversationAccount)
 {
     ServiceUrl          = serviceUrl;
     ChannelId           = channelId;
     ChannelAccount      = channelAccount;
     ConversationAccount = conversationAccount;
     ConversationStatus  = ConverstationStatusOptions.Active;
     LastUpdated         = DateTime.Now;
 }
        // Check if user using the app is a valid SME or not
        private async Task <bool> IsMemberOfSmeTeamAsync(ITurnContext <IInvokeActivity> turnContext)
        {
            var teamId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.TeamId);

            bool isUserPartOfRoster = false;

            try
            {
                ConversationAccount conversationAccount = new ConversationAccount();
                conversationAccount.Id = teamId;

                ConversationReference conversationReference = new ConversationReference();
                conversationReference.ServiceUrl   = turnContext.Activity.ServiceUrl;
                conversationReference.Conversation = conversationAccount;

                string currentUserId = turnContext.Activity.From.Id;

                // Check for current user id in cache and add id of current user to cache if they are not added before
                // once they are validated againt SME roster
                if (!this.accessCache.TryGetValue(currentUserId, out string membersCacheEntry))
                {
                    await this.botAdapter.ContinueConversationAsync(
                        this.appID,
                        conversationReference,
                        async (newTurnContext, newCancellationToken) =>
                    {
                        var members = await this.botAdapter.GetConversationMembersAsync(newTurnContext, default(CancellationToken));
                        foreach (var member in members)
                        {
                            if (member.Id.Equals(currentUserId))
                            {
                                membersCacheEntry  = member.Id;
                                isUserPartOfRoster = true;

                                var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromDays(this.accessCacheExpiryInDays));
                                this.accessCache.Set(currentUserId, membersCacheEntry, cacheEntryOptions);
                                break;
                            }
                        }
                    },
                        default(CancellationToken));
                }
                else
                {
                    isUserPartOfRoster = true;
                }
            }
            catch (Exception error)
            {
                this.telemetryClient.TrackTrace($"Failed to get members of team {teamId}: {error.Message}", ApplicationInsights.DataContracts.SeverityLevel.Error);
                this.telemetryClient.TrackException(error);
                isUserPartOfRoster = false;
            }

            return(isUserPartOfRoster);
        }
        public IList <Activity> GetActivityFromConversationLogs(IEnumerable <ChatReportModel> reports)
        {
            if (reports == null)
            {
                return(null);
            }

            ConversationReference selfConversation           = _currentActivity.GetConversationReference();
            IList <Activity>      replayTranscriptActivities = new List <Activity>();
            List <string>         listBroadcastIds           = new List <string>();
            ConversationAccount   conversationAccount        = new ConversationAccount(null, null, _currentActivity.Conversation.Id, null, null);

            foreach (ChatReportModel report in reports)
            {
                foreach (ChatReportLogModel reportLog in report.ReportLogs)
                {
                    Activity activityLog = new Activity();
                    activityLog.ApplyConversationReference(selfConversation);

                    //Dealing with broadcast. If broadcast, we ensure that the message is only send once
                    if (reportLog.IsBroadcast)
                    {
                        if (!listBroadcastIds.Contains(reportLog.Id))
                        {
                            listBroadcastIds.Add(reportLog.Id);
                            activityLog.ChannelData = CommandFactoryHelper.CreateCommandSendMessage(
                                selfConversation.Bot.Id, "*", reportLog.From, reportLog.ReportType);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        activityLog.ChannelData = CommandFactoryHelper.CreateCommandSendMessage(
                            selfConversation.Bot.Id, report.User.Id, reportLog.From, reportLog.ReportType);
                    }

                    //Rest of the message
                    activityLog.Id             = reportLog.Id;
                    activityLog.ReplyToId      = null;
                    activityLog.Text           = reportLog.Message;
                    activityLog.Type           = ActivityTypes.Message;
                    activityLog.Conversation   = conversationAccount;
                    activityLog.Timestamp      = reportLog.Date;
                    activityLog.LocalTimestamp = reportLog.Date;
                    replayTranscriptActivities.Add(activityLog);
                }
            }

            return(replayTranscriptActivities.OrderBy(p => p.Timestamp).ToList());
        }
        public IMessageActivity CreateMessage(ConversationAccount conversation, string text)
        {
            var msg = Activity.CreateMessageActivity();

            msg.From         = new ChannelAccount("177b2eem05dc4542ac", "Bot");
            msg.Recipient    = new ChannelAccount("default-user", "default-user");
            msg.Conversation = conversation;
            msg.ServiceUrl   = "http://localhost:3979/api/messages";
            msg.Text         = text;

            return(msg);
        }
Beispiel #22
0
        internal static IList <Activity> CreateActivitySetWithOneActivityThatHasSetProperties(string id = null, string conversationId = null, DateTime?created = null, string fromProperty = null, string text = null, object channelData = null, IList <Attachment> attachments = null, string eTag = null)
        {
            var conversation = new ConversationAccount(id: conversationId);
            var from         = new ChannelAccount(name: fromProperty);

            var matchingActivity = new Activity(id: id, conversation: conversation, timestamp: created ?? DateTime.UtcNow, fromProperty: from, text: text,
                                                channelData: channelData, attachments: attachments);
            var activities = CreateRandomActivities();

            activities.Add(matchingActivity);
            return(activities);
        }
Beispiel #23
0
        public IMessageActivity CreateMessage(ConversationAccount conversation, string text)
        {
            var msg = Activity.CreateMessageActivity();

            msg.From         = new ChannelAccount(botId, "Bot");
            msg.Recipient    = new ChannelAccount("default-user", "default-user");
            msg.Conversation = conversation;
            msg.ServiceUrl   = svcUrl;
            msg.Text         = text;

            return(msg);
        }
        private static Activity CreateHandoffEvent(string name, object value, ConversationAccount conversation)
        {
            var handoffEvent = Activity.CreateEventActivity() as Activity;

            handoffEvent.Name         = name;
            handoffEvent.Value        = value;
            handoffEvent.Id           = Guid.NewGuid().ToString();
            handoffEvent.Timestamp    = DateTime.UtcNow;
            handoffEvent.Conversation = conversation;
            handoffEvent.Attachments  = new List <Attachment>();
            handoffEvent.Entities     = new List <Entity>();
            return(handoffEvent);
        }
        public void TeamsMeetingParticipantInits()
        {
            var user         = new TeamsChannelAccount("*****@*****.**", "Joe", "Joe", "Smith", "*****@*****.**", "joePrincipalName");
            var conversation = new ConversationAccount(true);
            var meeting      = new MeetingParticipantInfo("owner", true);

            var participant = new TeamsMeetingParticipant(user, conversation, meeting);

            Assert.NotNull(participant);
            Assert.IsType <TeamsMeetingParticipant>(participant);
            Assert.Equal(user, participant.User);
            Assert.Equal(conversation, participant.Conversation);
            Assert.Equal(meeting, participant.Meeting);
        }
Beispiel #26
0
        internal static List <Activity> CreateRandomActivities()
        {
            var activities = new List <Activity>();
            var now        = DateTime.UtcNow;

            for (var i = 0; i < 5; i++)
            {
                var dt           = now.AddSeconds(-1);
                var conversation = new ConversationAccount(id: $"conversationId{i}");
                var from         = new ChannelAccount(name: $"fromProperty{i}");
                activities.Add(new Activity(id: $"id{i}", conversation: conversation, timestamp: dt, fromProperty: from, text: $"text{i}"));
            }
            return(activities);
        }
        // Default locale intentionally oddly-cased to check that it isn't defaulted somewhere, but tests stay in English
        private static Activity CreateActivity(string locale, bool createRecipient = true, bool createFrom = true)
        {
            var account1 = createFrom ? new ChannelAccount
            {
                Id         = "ChannelAccount_Id_1",
                Name       = "ChannelAccount_Name_1",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ChannelAccount_Role_1",
            }
            : null;

            var account2 = createRecipient ? new ChannelAccount
            {
                Id         = "ChannelAccount_Id_2",
                Name       = "ChannelAccount_Name_2",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ChannelAccount_Role_2",
            }
            : null;

            var conversationAccount = new ConversationAccount
            {
                ConversationType = "a",
                Id         = "123",
                IsGroup    = true,
                Name       = "Name",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ConversationAccount_Role",
            };

            var activity = new Activity
            {
                Id           = "123",
                From         = account1,
                Recipient    = account2,
                Conversation = conversationAccount,
                ChannelId    = "ChannelId123",
                Locale       = locale,
                ServiceUrl   = "ServiceUrl123",
            };

            return(activity);
        }
Beispiel #28
0
        public virtual Party ToParty()
        {
            ChannelAccount channelAccount = string.IsNullOrEmpty(ChannelAccountId)
                ? null : new ChannelAccount(ChannelAccountId, ChannelAccountName);

            ConversationAccount conversationAccount = new ConversationAccount(null, ConversationAccountId, ConversationAccountName);

            Party party = new Party(ServiceUrl, ChannelId, channelAccount, conversationAccount)
            {
                ConnectionRequestTime     = DateTimeFromString(ConnectionRequestTime),
                ConnectionEstablishedTime = DateTimeFromString(ConnectionEstablishedTime)
            };

            return(party);
        }
Beispiel #29
0
        public virtual Party FindBotPartyByChannelAndConversation(string channelId, ConversationAccount conversationAccount)
        {
            Party botParty = null;

            try
            {
                botParty = BotParties.Single(party =>
                                             (party.ChannelId.Equals(channelId) &&
                                              party.ConversationAccount.Id.Equals(conversationAccount.Id)));
            }
            catch (InvalidOperationException)
            {
            }

            return(botParty);
        }
Beispiel #30
0
        private Activity CreateActivity()
        {
            var account1 = new ChannelAccount
            {
                Id         = "ChannelAccount_Id_1",
                Name       = "ChannelAccount_Name_1",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ChannelAccount_Role_1",
            };

            var account2 = new ChannelAccount
            {
                Id         = "ChannelAccount_Id_2",
                Name       = "ChannelAccount_Name_2",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ChannelAccount_Role_2",
            };

            var conversationAccount = new ConversationAccount
            {
                ConversationType = "a",
                Id         = "123",
                IsGroup    = true,
                Name       = "Name",
                Properties = new JObject {
                    { "Name", "Value" }
                },
                Role = "ConversationAccount_Role",
            };

            var activity = new Activity
            {
                Id           = "123",
                From         = account1,
                Recipient    = account2,
                Conversation = conversationAccount,
                ChannelId    = "ChannelId123",
                Locale       = "en-uS", // Intentionally oddly-cased to check that it isn't defaulted somewhere, but tests stay in English
                ServiceUrl   = "ServiceUrl123",
            };

            return(activity);
        }