是否可以让Lync与REST API通信?

时间:2015-03-24 15:14:53

标签: rest post web lync lync-2013

我已经创建了一个基本的REST API,用户可以要求提供首字母缩略词,网页将通过POST调用返回首字母缩略词的含义。

我的大多数最终用户都不像使用Microsoft Lync应用程序那样使用Internet。

我是否可以创建Lync帐户,并将问题传递给我的API,并将答案返回给用户?这意味着用户只需在Lync中打开一个新聊天而不是新的网页。

我确信这是可能的,但我无法在Google或网络上找到任何信息。如何实现这一目标?

非常感谢。

编辑:

为了某人创造一个简单的例子而希望增加赏金,因为我相信它对于大量的开发者来说非常有用:)。

4 个答案:

答案 0 :(得分:5)

是的,绝对的。 UCMA(统一通信管理API)将是我在这里使用的API的选择,也是一个好的起点 - UCMA应用程序是“普通”.net应用程序,但也暴露了一个应用程序端点,可以添加到用户的联系人名单。当用户发送消息时,可以触发应用程序中的事件,以便您可以接收传入的IM,执行首字母缩略词翻译并返回完整的措辞。

我有很多关于UCMA的博客文章,但截至目前尚无定义的“有用”帖子集合,但即将推出!在此期间,请随意browse the list

- 汤姆

答案 1 :(得分:4)

要详细说明Tom Morgan的答案,为此创建一个UCMA应用程序会很容易。

创建UCMA应用程序

现在这并不复杂。由于您只想接收InstantMessage并回复它,因此您不需要受信任应用程序的全部功能。我的选择是使用简单的UserEndpoint。幸运的是,Tom在网上有一个很好的例子:Simplest example using UCMA UserEndpoint to send an IM

让它收听收到的消息

虽然示例应用程序在连接时发送消息,但我们需要收听消息。在UserEndpoint上,为即时消息设置消息处理程序:

endpoint.RegisterForIncomingCall<InstantMessagingCall>(HandleInstantMessagingCall);

private void HandleInstantMessagingCall(object sender, CallReceivedEventArgs<InstantMessagingCall> e)
{
    // We need the flow to be able to send/receive messages.
    e.Call.InstantMessagingFlowConfigurationRequested += HandleInstantMessagingFlowConfigurationRequested;
    // And the message should be accepted.
    e.Call.BeginAccept(ar => {
        e.Call.EndAccept(ar);

        // Grab and handle the toast message here.

    }, null);
}

处理消息

这里有一点点复杂,你的第一条信息可能出现在&#39; toast&#39;新消息参数,或稍后到达消息流(流程)。

处理Toast消息

toast消息是会话设置的一部分,但它可以为null或不是文本消息。

 if (e.ToastMessage != null && e.ToastMessage.HasTextMessage)
 {
      var message = e.ToastMessage.Message;

      // Here message is whatever initial text the 
      // other party send you.

      // Send it to your Acronym webservice and 
      // respond on the message flow, see the flow
      // handler below.
 }

处理流程

您的消息流是传递实际数据的地方。掌握流程并存储它,因为以后需要发送消息。

private void HandleHandleInstantMessagingFlowConfigurationRequested(object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
{
    // Grab your flow here, and store it somewhere.
    var flow = e.Flow;
    // Handle incoming messages
    flow.MessageReceived += HandleMessageReceived;
}

创建一个消息处理程序来处理传入的消息:

private void HandleMessageReceived(object sender, InstantMessageReceivedEventArgs e)
{
    if (e.HasTextBody)
    {
        var message = e.TextBody;

        // Send it to your Acronym webservice and respond 
        // on the message flow.

        flow.BeginSendInstantMessage(
            "Your response", 
            ar => { flow.EndSendInstantMessage(ar); }, 
            null);
    }
}

这将总结发送/接收消息的最基本示例。如果有任何部分需要更多说明,请告诉我,我可以在需要的地方添加答案。

我用完整的解决方案创建了一个Gist。遗憾的是,它没有经过测试,因为我目前还没有接近Lync开发环境。请参阅UCMA UserEndpoint replying to IM Example.cs

答案 2 :(得分:0)

我从未使用过Lync,但是当我查看开发文档时,我偶然发现了一个可能是您正在寻找的样本。

Lync 2013: Filter room messages before they are posted

过滤完邮件后,您只需要抓住首字母缩略词并调用调用API的自定义代码。

除非我遗漏了某些内容,否则我认为您也可以通过简单的GET请求来完成。只需像yoursite.com/api/acronym/[the_acronym_here]一样调用您的API。

答案 3 :(得分:0)

您可以使用UCWA(Microsoft统一通信Web API),是一个REST API。有关详细信息,可以参考以下内容。

https://ucwa.lync.com/documentation/what-is-lync-ucwa-api