protected void BeginConversation(SalesAgent agent, Contact contact)
        {
            // Conversation participant list.
            List <string> participantList = new List <string>();

            participantList.Add(agent.Uri);

            Dictionary <AutomationModalitySettings, object> conversationContextData = new Dictionary <AutomationModalitySettings, object>();

            // initial IM message
            conversationContextData.Add(AutomationModalitySettings.FirstInstantMessage, "Apress Remodeling Application Context");

            // send initial IM immediately
            conversationContextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);

            // set application ID
            conversationContextData.Add(AutomationModalitySettings.ApplicationId, "{A07EE104-A0C2-4E84-ABB3-BBC370A37636}");

            string appData = "ContactID=" + contact.contactID + "|CustomerID=" + contact.customerID;

            // set application data
            conversationContextData.Add(AutomationModalitySettings.ApplicationData, appData);

            Automation auto = LyncClient.GetAutomation();

            // start the conversation.
            IAsyncResult beginconversation = auto.BeginStartConversation(
                AutomationModalities.InstantMessage
                , participantList
                , conversationContextData
                , null
                , null);
        }
Beispiel #2
0
        /// <summary>
        /// Returns list of SalesAgents from Sharepoint
        /// </summary>
        /// <returns></returns>
        public List <SalesAgent> GetAgents()
        {
            List <SalesAgent> agents = new List <SalesAgent>();

            try
            {
                foreach (ListItem listItem in GetListItems("Agent", ""))
                {
                    SalesAgent newAgent = new SalesAgent()
                    {
                        displayName  = listItem["AgentName"].ToString(),
                        email        = listItem["SipAddress"].ToString(),
                        login        = listItem["Login"].ToString(),
                        lastMessage  = (listItem["LastMessage"] ?? string.Empty).ToString(),
                        onlineStatus = listItem["AgentStatus"].ToString()
                    };

                    agents.Add(newAgent);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(agents);
        }
        protected void ProcessMailItems()
        {
            //Get mailbox items
            ItemView itemView = new ItemView(10);

            itemView.PropertySet = PropertySet.IdOnly;

            FindItemsResults <Item> mailItems       = _service.FindItems(WellKnownFolderName.Inbox, itemView);
            PropertySet             emailProperties = new PropertySet(
                EmailMessageSchema.Sender,
                EmailMessageSchema.DateTimeReceived,
                EmailMessageSchema.Body,
                EmailMessageSchema.Subject);

            emailProperties.RequestedBodyType = BodyType.Text;
            if (mailItems.TotalCount > 0)
            {
                _service.LoadPropertiesForItems(mailItems.Items, emailProperties);
            }

            List <ItemId> emailItemIDs = new List <ItemId>();

            //process each mailbox item
            foreach (Item mailItem in mailItems)
            {
                if (mailItem is EmailMessage)
                {
                    //find or create customer in sharepoint database
                    EmailMessage email    = (EmailMessage)mailItem;
                    Customer     customer = _context.GetCustomerByEmail(email.Sender.Address);
                    if (customer == null)
                    {
                        Customer newCustomer = new Customer()
                        {
                            name   = email.Sender.Name,
                            email  = email.Sender.Address,
                            status = "Prospect"
                        };

                        customer = _context.CreateNewCustomer(newCustomer);
                    }

                    //create contact record from email
                    Contact newContact = new Contact()
                    {
                        customerID   = customer.customerID,
                        contactDate  = email.DateTimeReceived.ToShortDateString(),
                        contactType  = "Email",
                        contactNotes = "Subject: " + email.Subject + "\n\n" + email.Body.Text
                    };

                    Contact savedContact = _context.CreatContact(newContact);

                    //assign agent
                    SalesAgent assignedAgent = (from A in _agents
                                                where A.onlineStatus == "Available"
                                                orderby A.lastMessage descending
                                                select A).FirstOrDefault();

                    if (assignedAgent != null)
                    {
                        //start lync conversation with contactid
                        BeginConversation(assignedAgent, savedContact);

                        //update lead count
                        _leadCount++;

                        //display updated lead count
                        Dispatcher.BeginInvoke(new Action(UpdateLeadCount));
                    }

                    //add item to list of items to get moved to Archive folder
                    emailItemIDs.Add(email.Id);
                }
            }

            if (emailItemIDs.Count > 0)
            {
                //move emails to archive folder
                //create search filter to find specific folder
                SearchFilter filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Archive");

                //use Exchange Web Service to search for folder
                Folder folder = _service.FindFolders(WellKnownFolderName.Inbox, filter, new FolderView(1)).Folders[0];

                //move email items to found folder
                _service.MoveItems(emailItemIDs, folder.Id);
            }
        }