Skip to content

Commit 941569a

Browse files
authored
Merge pull request microsoft#152 from adilei/master
Support for regional settings for Directline
2 parents b004bb3 + b74ae75 commit 941569a

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,5 @@ ASALocalRun/
329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331331
/sabacha/Dispatcher/dispatcher.bot
332+
SharePointSSOComponent/package-lock.json
333+
SharePointSSOComponent/config/serve.json

SharePointSSOComponent/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SharePoint SSO Component
22

3-
This code sample that demonstrates how to create a SharePoint SPFx component which is a wrapper for a copilot, created with Microsoft Copilot Studio. The SPFx component included in the sample supports SSO, providing seamless user authentication for users interacting with the copilot.
3+
This code sample demonstrates how to create a SharePoint SPFx component which is a wrapper for a copilot, created with Microsoft Copilot Studio. The SPFx component included in the sample supports SSO, providing seamless authentication for users interacting with the copilot.
44

55
## Getting Started
66

SharePointSSOComponent/src/extensions/pvaSso/components/ChatBot.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export const PVAChatbotDialog: React.FunctionComponent<IChatbotProps> = (props)
3333
// Your bot's token endpoint
3434
const botURL = props.botURL;
3535

36+
// constructing URL using regional settings
37+
const environmentEndPoint = botURL.slice(0,botURL.indexOf('/powervirtualagents'));
38+
const apiVersion = botURL.slice(botURL.indexOf('api-version')).split('=')[1];
39+
const regionalChannelSettingsURL = `${environmentEndPoint}/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`;
40+
3641
// Using refs instead of IDs to get the webchat and loading spinner elements
3742
const webChatRef = useRef<HTMLDivElement>(null);
3843
const loadingSpinnerRef = useRef<HTMLDivElement>(null);
@@ -59,15 +64,29 @@ export const PVAChatbotDialog: React.FunctionComponent<IChatbotProps> = (props)
5964

6065
const token = responseToken?.accessToken || null;
6166

62-
// Create DirectLine object
63-
const response = await fetch(botURL);
67+
// Get the regional channel URL
68+
let regionalChannelURL;
69+
70+
const regionalResponse = await fetch(regionalChannelSettingsURL);
71+
if(regionalResponse.ok){
72+
const data = await regionalResponse.json();
73+
regionalChannelURL = data.channelUrlsById.directline;
74+
}
75+
else {
76+
console.error(`HTTP error! Status: ${regionalResponse.status}`);
77+
}
78+
6479

80+
// Create DirectLine object
6581
let directline: any;
6682

83+
const response = await fetch(botURL);
84+
6785
if (response.ok) {
6886
const conversationInfo = await response.json();
6987
directline = ReactWebChat.createDirectLine({
7088
token: conversationInfo.token,
89+
domain: regionalChannelURL + 'v3/directline',
7190
});
7291
} else {
7392
console.error(`HTTP error! Status: ${response.status}`);

0 commit comments

Comments
 (0)