如何使用Powershell从Lync Conversation获取消息?



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

请参阅使用 powershell 发送接收 Lync/Skype for Business 消息的示例(作者:Grzegorz Kulikowski(

与其他用户一起测试

cd "C:Program Files (x86)Microsoft OfficeOffice15lyncsdkAssembliesDesktop"
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 OfficeOffice15lyncsdkAssembliesDesktop"
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++
}

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

在对话中发送和接收文本

了解 Skype Web SDK 第 15 天:接收即时消息

最新更新