Lync 二次开发-对单个联络人和联系人组发送即时消息

41 篇文章 0 订阅
4 篇文章 0 订阅

对单个联系人发送消息此方法只是弹出联系人聊天对话框(对方在线时),并没有发送出消息      

[ScriptableMember]
        public void CallSingleMsg(string sipUri)
        {
            var lyncAutomation = LyncClient.GetAutomation();

            var inviteeList = new string[] { sipUri };
            var modalitySettings = new Dictionary();
            modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, false);
            if (string.IsNullOrEmpty(""))
            {
                modalitySettings.Add(AutomationModalitySettings.Subject, "");
            }

            lyncAutomation.BeginStartConversation(
                AutomationModalities.InstantMessage,
                inviteeList,
                modalitySettings,
                (ar) => { if (ar.IsCompleted) { ((Automation)ar.AsyncState).EndStartConversation(ar); } },
                lyncAutomation);

        }

 

对通讯组发送即时消息

[ScriptableMember]
        public void CallGroupMsg(string sipUri)
        {
            LyncClient client = LyncClient.GetClient();
            Automation lyncAutomation = LyncClient.GetAutomation();
            List inviteeList = new List();
            InstantMessageModality m = null;
            Conversation conversation = conversation = client.ConversationManager.AddConversation();

            //异步查询出联系人取出sipuri 添加到sip地址集合
            client.ContactManager.BeginLookup(sipUri, (ir) =>
            {
                try
                {
                    object foundItem = client.ContactManager.EndLookup(ir);
                    if (foundItem.GetType().Name == "DistributionGroup")
                    {
                        Group foundGroup = foundItem as Group;
                        foreach (var item in foundGroup)
                        {
                            inviteeList.Add(item.Uri);
                        }
                    }
                    else
                    {
                        Contact foundContact = foundItem as Contact;
                    }
                }
                catch (ItemNotFoundException)
                {
                    MessageBox.Show("Lookup returned no results");
                }


            }, null);

            var modalitySettings = new Dictionary();
            modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, false);
            if (string.IsNullOrEmpty(""))
            {
                modalitySettings.Add(AutomationModalitySettings.Subject, "");
            }

            //开始会话

            lyncAutomation.BeginStartConversation(
                AutomationModalities.InstantMessage,
                inviteeList,
                modalitySettings,
                (ar) => { if (ar.IsCompleted) { ((Automation)ar.AsyncState).EndStartConversation(ar); } },
                lyncAutomation);
        }


/// <summary>
        /// 发送即时消息
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="uri"></param>
        private void AddConversion(LyncClient lc, string uri)
        {
            Contact contact = lc.ContactManager.GetContactByUri(uri);
            ContactAvailability availability = (ContactAvailability)contact.GetContactInformation(ContactInformationType.Availability);
            Conversation conversation = lc.ConversationManager.AddConversation();
            conversation.AddParticipant(contact);
            InstantMessageModality m = (InstantMessageModality)conversation.Modalities[ModalityTypes.Invalid];
            m.BeginConnect(null, null);
        }


        /// <summary>
        /// 弹出联系人聊天对话框(无论对方是否在线)
        /// </summary>
        /// <param name="sipUri"></param>
        public void CallSingleMsg(string sipUri)
        {
            var lyncAutomation = LyncClient.GetAutomation();
            var inviteeList = new string[] { sipUri };
            var modalitySettings = new Dictionary<AutomationModalitySettings,object>();
            modalitySettings.Add(AutomationModalitySettings.Subject, false);
            lyncAutomation.BeginStartConversation(
                AutomationModalities.InstantMessage,
                inviteeList,
                modalitySettings,
                (ar) => { if (ar.IsCompleted) { ((Automation)ar.AsyncState).EndStartConversation(ar); } },
                lyncAutomation);
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值