【问题标题】:Is it possible to have Lync communicate with a REST API?是否可以让 Lync 与 REST API 通信?
【发布时间】:2015-05-27 23:31:22
【问题描述】:

我创建了一个基本的 REST API,用户可以在其中请求首字母缩略词,网页将通过 POST 调用返回首字母缩略词的含义。

我的大多数最终用户使用 Internet 的次数不如使用 Microsoft Lync 应用程序的次数多。

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

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

非常感谢。

编辑:

添加赏金以希望有人创建一个简单的示例,因为我相信这对大量开发人员来说非常有用:)。

【问题讨论】:

    标签: rest post web lync lync-2013


    【解决方案1】:

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

    创建一个 UCMA 应用程序

    现在这不必复杂。由于您只想接收即时消息并回复它,因此您不需要受信任应用程序的全部功能。我的选择是使用简单的UserEndpoint。幸运的是,汤姆在网上有一个很好的例子: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);
    }
    

    处理消息

    这里有点复杂,您的第一条消息可以在新消息参数的“toast”中,或者稍后到达消息流(流)。

    处理 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

    【讨论】:

    • @Willen Duncan 非常感谢您的回复,我将在周末使用它来尝试创建解决方案 - 不胜感激! :)
    【解决方案2】:

    你可以使用UCWA(Microsoft Unified Communications Web API),它是一个REST API。详情可以参考如下..

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

    【讨论】:

      【解决方案3】:

      我从未使用过 Lync,但在查看开发文档时,我偶然发现了一个示例,这可能就是您正在寻找的。​​p>

      Lync 2013: Filter room messages before they are posted

      过滤消息后,您只需要捕获首字母缩写词并调用调用 API 的自定义代码。

      除非我遗漏了什么,否则我认为您也可以使用简单的 GET 请求来完成。只需像这样yoursite.com/api/acronym/[the_acronym_here] 调用您的 API。

      【讨论】:

        【解决方案4】:

        是的,当然。 UCMA(统一通信托管 API)将是我在这里使用的 API 的选择,也是一个很好的起点 - UCMA 应用程序是“普通”的 .net 应用程序,但也公开了一个应用程序端点,可以将其添加到用户的联系人中列表。当用户发送消息时,可能会触发您的应用程序中的事件,因此您可以接收传入的 IM、进行首字母缩写词翻译并返回完整的措辞。

        我有一堆关于 UCMA 的博文,但目前还没有明确的“有用”博文集合供您阅读,但很快就会发布!同时,请随时browse the list

        -汤姆

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-05-26
          • 1970-01-01
          • 2021-09-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多