Sim*_*ely 16 rest post lync web lync-2013
我已经创建了一个基本的REST API,用户可以在其中请求首字母缩略词,并且网页将通过POST调用返回首字母缩略词的含义.
我的大多数最终用户都不像使用Microsoft Lync应用程序那样使用Internet.
我是否可以创建一个Lync帐户,并将问题传递给我的API,并将答案返回给用户?这意味着用户只需在Lync中打开新聊天而不是新的网页.
我确信这是可能的,但我无法在Google或网络上找到任何信息.如何实现这一目标?
非常感谢.
编辑:
为了有人创造一个简单的例子而希望增加赏金,因为我相信它对于大量的开发人员来说非常有用:).
为了详细说明Tom Morgan的答案,为此创建一个 UCMA 应用程序将很容易。
现在这不必太复杂。由于您想要的只是接收即时消息并回复它,因此您不需要受信任的应用程序的全部功能。我的选择是使用一个简单的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);
}
Run Code Online (Sandbox Code Playgroud)
这里有一点复杂,您的第一条消息可以位于新消息参数的“toast”中,或者稍后到达消息流(流)。
Toast 消息是对话设置的一部分,但它可以为空或不是文本消息。
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.
}
Run Code Online (Sandbox Code Playgroud)
您的消息流是实际数据传递的地方。获取流的句柄并存储它,因为稍后需要它来发送消息。
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;
}
Run Code Online (Sandbox Code Playgroud)
并创建一个消息处理程序来处理传入的消息:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是发送/接收消息的最基本示例的总结。如果其中的任何部分需要更多说明,请告诉我,我可以在需要时添加到答案中。
我创建了一个包含完整解决方案的要点。遗憾的是它没有经过测试,因为我目前不在 Lync 开发环境附近。看UCMA UserEndpoint replying to IM Example.cs。
| 归档时间: |
|
| 查看次数: |
4260 次 |
| 最近记录: |