(Lync SDK received text)
前に、相手を指定して、新しい会話を始めるサンプルを作成しました。
会話作成後に交わされたIMをキャプチャしてみます。
準備
LyncSDKをインストールすると、WPFとSilverlightのプロジェクトテンプレートが作成されますが、それを使わずにCosnoleApplicationで実装します。
UIフレームワークは不要なでの参照するアセンブリは2つです。
Microsoft.Lync.Model
Microsoft.Lync.Utilities
が参照追加のダイヤログには出てきません。
アセンブリを直接参照して追加する必要があります。
C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll
C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Utilities.dll
実装
IM画面を新しい会話でスタート
Automation automation = LyncClient.GetAutomation(); // IMを送る相手を設定する。 // 複数人に送る場合にはその人数だけリストに追加 List<string> inviteeList = new List<string>(); inviteeList.Add("ninomiya@sample.com"); // IM送信時のオプション設定を構築 var modalitySettings = new Dictionary<AutomationModalitySettings, object>(); modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); // 呼び出し IAsyncResult ar = automation.BeginStartConversation( AutomationModalities.InstantMessage , inviteeList , modalitySettings , null , null); //新しく開いたウィンドを取得 ConversationWindow conversationWindow = automation.EndStartConversation(ar);
ConversationWindow
新しく開いたIM画面を操作するためのウィンドです。
参加者の情報取得や追加退席、各種変更イベント登録はConversationWindowに行います。
IM受信イベント登録
//メッセージ受信の処理を、IM参加者ごとにイベントを登録 foreach (Participant participant in conversationWindow.Conversation.Participants) { // IM を取得 InstantMessageModality im = participant.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality; // IM 受信の際のイベント処理を登録 im.InstantMessageReceived += ImModality_InstantMessageReceived; }
ModalityTypes
IM画面には、IM送受信以外にもファイル共有や音声ビデオなど複数の機能が含まれています。
その機能毎に、Modalityが分かれています。
ModalityTypes enumeration (Microsoft.Lync.Model.Conversation)
定義名 | 和訳 |
InstantMessage | インスタントメッセージングのモダリティ |
AudioVideo | オーディオ/ビデオモダリティ |
ApplicationSharing | アプリケーション共有のモダリティ |
ContentSharing | コンテンツ共有のモダリティ |
メッセージ受信のイベント(ImModality_InstantMessageReceived)
private void ImModality_InstantMessageReceived(object sender, MessageSentEventArgs e) { //IM取得 InstantMessageModality instantMessageModality = sender as Microsoft.Lync.Model.Conversation.InstantMessageModality; //送信者の名前を取得 var senderName = instantMessageModality.Participant.Contact.GetContactInformation(ContactInformationType.DisplayName); //画面に表示 Console.WriteLine(senderName + ":" + e.Text); }
(∩´∀`)∩ワーイ
IM参加者ごとにイベント登録が必要な件と送信者情報の取得する件で若干悩みましたが無事にできましま。