@@ -11,9 +11,8 @@ namespace Microsoft.Azure.Agent;
11
11
12
12
internal class ChatSession : IDisposable
13
13
{
14
- // TODO: production URL not yet working for some regions.
15
- // private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01";
16
- private const string ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01" ;
14
+ private const string PROD_ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01" ;
15
+ private const string TEST_ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01" ;
17
16
private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15" ;
18
17
private const string CONVERSATION_URL = "https://directline.botframework.com/v3/directline/conversations" ;
19
18
@@ -141,11 +140,13 @@ private async Task<string> SetupNewChat(IStatusContext context, CancellationToke
141
140
142
141
private async Task CheckAuthorizationAsync ( CancellationToken cancellationToken )
143
142
{
144
- HttpRequestMessage request = new ( HttpMethod . Get , ACCESS_URL ) ;
145
- request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
146
- request . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , _accessToken . Token ) ;
147
-
148
- HttpResponseMessage response = await _httpClient . SendAsync ( request , cancellationToken ) ;
143
+ HttpResponseMessage response = await SendRequestAsync ( PROD_ACCESS_URL ) ;
144
+ if ( response . StatusCode is not System . Net . HttpStatusCode . OK )
145
+ {
146
+ // We fall back to the test endpoint when the prod endpoint is unavailable.
147
+ Telemetry . Trace ( AzTrace . Exception ( $ "Prod access endpoint unavailable. HTTP status: { response . StatusCode } . Fall back to canary endpoint.") ) ;
148
+ response = await SendRequestAsync ( TEST_ACCESS_URL ) ;
149
+ }
149
150
await response . EnsureSuccessStatusCodeForTokenRequest ( "Failed to check Copilot authorization." ) ;
150
151
151
152
using Stream stream = await response . Content . ReadAsStreamAsync ( cancellationToken ) ;
@@ -158,6 +159,14 @@ private async Task CheckAuthorizationAsync(CancellationToken cancellationToken)
158
159
Telemetry . Trace ( AzTrace . Exception ( message ) ) ;
159
160
throw new TokenRequestException ( message ) { UserUnauthorized = true } ;
160
161
}
162
+
163
+ async Task < HttpResponseMessage > SendRequestAsync ( string url )
164
+ {
165
+ HttpRequestMessage request = new ( HttpMethod . Get , url ) ;
166
+ request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
167
+ request . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , _accessToken . Token ) ;
168
+ return await _httpClient . SendAsync ( request , cancellationToken ) ;
169
+ }
161
170
}
162
171
163
172
private async Task GetInitialDLTokenAsync ( CancellationToken cancellationToken )
0 commit comments