You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#中Azure.AI/Azure.Communication的ChatMessage等类型失效,求替代方案

技术求助:Azure相关依赖版本更新导致类型弃用问题

我按照某视频及GitHub项目文档开发,已完成全部环境配置。该项目最后更新于7个月前,使用当前最新依赖版本时,ChatMessage、CognitiveServicesEndpoint等类型疑似被弃用,但找不到官方文档说明对应的替代类型。尝试安装其他库、调整配置都没解决,求技术支持。

相关代码片段:

var cloudEvents = await context.Request.ReadFromJsonAsync<CloudEvent[]>() ?? Array.Empty<CloudEvent>();
var contextId = context.Request.RouteValues["contextId"]?.ToString() ?? "";
var callerId = context.Request.Query["callerId"].ToString() ?? "";

foreach (var cloudEvent in cloudEvents)
{
    // Parse the cloud event to get the call event details
    CallAutomationEventBase callEvent = CallAutomationEventParser.Parse(cloudEvent);
    var callConnection = callClient.GetCallConnection(callEvent.CallConnectionId);
    var callConnectionMedia = callConnection.GetCallMedia();

    var messages = chatSessions[contextId];

    var phoneId = new PhoneNumberIdentifier(callerId); 

    if (callEvent is CallConnected)
    {
        // If the call is connected, get a response from the chatbot and send it to the user
        var response = await GetChatGPTResponse(messages);
        messages.Add(new ChatMessage(ChatRole.Assistant, response));
        await SayAndRecognize(callConnectionMedia, phoneId, response);
    }
    if (callEvent is RecognizeCompleted recogEvent 
        && recogEvent.RecognizeResult is SpeechResult speech_result)
    {
        // If speech is recognized, get a response from the chatbot based on the recognized speech and send it to the user
        messages.Add(new ChatMessage(ChatRole.User, speech_result.Speech));
        
        var response = await GetChatGPTResponse(messages);
        messages.Add(new ChatMessage(ChatRole.Assistant, response));
        await SayAndRecognize(callConnectionMedia, phoneId, response);
    }                 
} 

内容的提问来源于stack exchange,提问作者Josh Walton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 07:44:57