如何使用PowerShell从lync对话中获取消息?

时间:2018-05-28 10:41:06

标签: powershell automation lync

我研究了一下,找到了利用Lync 2013 SDK将IM发送到联系人列表中的联系人的方法。但如果有一种方法可以从对话窗口获取消息,那将会更有用。

1 个答案:

答案 0 :(得分:0)

Sample send receive Lync / Skype for business messages using powershell(作者:Grzegorz Kulikowski)

与其他用户进行测试

cd "C:\Program Files (x86)\Microsoft Office\Office15\lyncsdk\Assemblies\Desktop"
Import-Module .\Microsoft.Lync.Model.dll
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
$Conversation = $client.ConversationManager.AddConversation()
$person=$client.ContactManager.GetContactByUri('person@domain.com')
$conversation.AddParticipant($person)


Get-EventSubscriber|Unregister-Event
# For each participant in the conversation

$conversation.Participants | Where { !$_.IsSelf } | foreach {
    Register-ObjectEvent -InputObject $_.Modalities[1] -EventName "InstantMessageReceived" -SourceIdentifier "person $i" -action { 
    $global:conv = $event
    $msg = $conv.SourceEventArgs.Text.trim()
    write-host $msg
    switch -Wildcard ($msg) {
     "What*" {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
     "Hello" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Hello human", {}, 0)}
     "stupid robot" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Humanity is overrated", {}, 0)}
    }
    }
    $i++
   }

自行测试

cd "C:\Program Files (x86)\Microsoft Office\Office15\lyncsdk\Assemblies\Desktop"
Import-Module .\Microsoft.Lync.Model.dll
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
$Conversation = $client.ConversationManager.AddConversation()
$conversation.AddParticipant($client.Self.Contact)

Get-EventSubscriber|Unregister-Event
  $conversation.Participants[0]| foreach {
    Register-ObjectEvent -InputObject $_.Modalities[1] -EventName "InstantMessageReceived" -SourceIdentifier "person $i" -action { 
    $global:conv = $event
    $msg = $conv.SourceEventArgs.Text.trim()
    write-host $msg
    #if ($msg -like 'What*') {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
    switch -Wildcard ($msg) {
     "What*" {$Conversation.Modalities['InstantMessage'].BeginSendMessage((Invoke-Expression $msg.split()[-1]), {}, 0)}
     "Hello" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Hello human", {}, 0)}
     "stupid robot" {$Conversation.Modalities['InstantMessage'].BeginSendMessage("Humanity is overrated", {}, 0)}
    }
    }
    $i++
   }

此外,这些可能有所帮助:

Send and receive text in a conversation

Learn Skype Web SDK Day 15 : Receiving Instant Messages