3

InstantMessageReceived イベントのハンドラーを設定していますが、着信ではなく発信テキスト メッセージでのみ発生するようです。ここに私が実行しているコードがあります:

# Register the app with Growl
$icon = "https://docs.google.com/uc?export=download&id=0B1Weg9ZlwneOZmY2b1NSVXJ0Q2s"
$types = '"new-im","new-call","invitation","share"'
& 'C:\Program Files (x86)\Growl for Windows\growlnotify.exe' /a:Lync /ai:$icon /r:$types "Registration."

#We just need the Model API for this example
import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.Dll"

#Get a reference to the Client object
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

#Set the client to reference to the local client
$self = $client.Self

# What do we do here?
$conversationMgr = $client.ConversationManager

# Register events for existing conversations.

$i = 0

for ($i=0; $i -lt $conversationMgr.Conversations.Count; $i++) {

Register-ObjectEvent -InputObject $conversationMgr.Conversations[$i].Modalities[1] -EventName "InstantMessageReceived" `
                    -SourceIdentifier "new im $i" `
                    -action {
                               $message = $EventArgs.Text
                               Write-Host "DEBUG: New incoming IM - $message"

                               # Try to get the name of the person...
                               $contactInfo = $Event.Sender.Conversation.Participants[1].Contact.GetContactInformation([Microsoft.Lync.Model.ContactInformationType[]] @("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress", "Photo", "IconUrl", "IconStream"))
                               $name = " "
                               if ($contactInfo.Get_Item("FirstName")) { $name = $contactInfo.Get_Item("FirstName") + " " + $contactInfo.Get_Item("LastName") + ":" }
                               elseif ($contactInfo.Get_Item("DisplayName")) { $name = $contactInfo.Get_Item("DisplayName") + ":"}
                               else { $name = $contactInfo.Get_Item("PrimaryEmailAddress") + ":" }

                               # We need to check if the Lync window (conversation?) has focus or not.
                               if (1) {
                                  # We need to send our growl notification.
                                  & 'C:\Program Files (x86)\Growl for Windows\growlnotify.exe' /a:Lync /n:new-im /t:"New Instant Message" "$name $message" 
                               }

                            }
}

# If this exits, no more events.
while (1) { }

他の誰かに IM メッセージを入力するたびに、着信メッセージに対して私がしようとしていることを実行します。しかし、発信するだけで、何も発火しません。私はすべてのドキュメントを確認しましたが、他に候補となるイベントはありません。これは間違いないと確信しています。しかし、Modality オブジェクトは、それが IM なのかスクリーン共有なのかなどについての情報を保存するだけで、何の役にも立ちません。

http://msdn.microsoft.com/en-us/library/lync/microsoft.lync.model.conversation.instantmessagemodality_di_3_uc_ocs14mreflyncclnt_members(v=office.14).aspx

これのどこを台無しにしていますか?私は Powershell での回答を好みますが、これは Powershell に固有の問題ではないと思うので、C# や Visual Basic などでそれを行う方法を知っていれば、それもありがたいです。

4

1 に答える 1

3

私は Lync を持っていないので、これを自分でテストできますが、API の使用方法が示されているこのリンクを見てください。

問題は、(私が理解していることから)メディアごとに参加者ごとにモダリティがあることです。したがって、テキストのみを使用する 2 人のメンバーとの会話の場合、2 つのモダリティがあり、1 つは (リモート参加者からの) 受信メッセージ用で、もう 1 つは送信用です。これはここで指定されています

インスタント メッセージが受信されたときに発生します。または、InstantMessageModality がローカルの参加者に属している場合は送信されます。

出典: MSDN

object-event を登録するときは、リモート モダリティではなく、「自分のモダリティ」に登録します。それを修正するには、マネージャーから各会話を取得する必要があるようです。あなたを代表する参加者を除く各参加者を見てください (IsSelfプロパティを確認してください)。次に、参加者 (自分を除く) からモダリティを受け取り、InstantMessageReceivedイベントに登録します。

少なくともそれは私が得たものですが、言ったように、私は Lync の経験がないので、簡単に間違っている可能性があります.

それがどのように行われるかについての私の推測(非常に未テスト):

# What do we do here?  You get the manager the keeps track of every conversation
$conversationMgr = $client.ConversationManager

# Register events for existing conversations.

#You may need to use '$conversation in $conversationMgr.GetEnumerator()'
foreach ($conversation in $conversationMgr) {

    #Get remote participants
    $conversation.Participants | where { !$_.IsSelf } | foreach {
        #Get IM modality
        $textmod = [InstantMessageModality]($_.Modalities[ModalityTypes.InstantMessage])

        Register-ObjectEvent -InputObject $textmod -EventName "InstantMessageReceived" `
                    -SourceIdentifier "new im $i" `
                    -action {
                            #...

        }
    }
}
于 2013-03-06T23:16:32.187 に答える