あなたの状況を解決する方法はいくつかあります。
私が理解しているように、クライアントがチャットボットウィジェットを使ってWebページに到着すると、そのユーザーはすでにWebページを通じてあなたのWebサイトで認証されています。
EDIT:Webページと埋め込みWebChatボックス間の通信を行う好ましい方法である3番目の方法を追加しました。
方法1:新しいダイアログを開始するには、サーバーの認証エンドポイントからの資格情報を使用しているにページ内のチャットボットにユーザーの資格情報(認証トークン)を転送する
一つの方法ユーザーと
しかし
、これが動作するため、にあなたはユーザーのIAddressが必要になります。言い換えれば、ユーザーはあなたのボットと以前に会話していなければならず、おそらくデータベースにどこかに格納しなければならなかったでしょう。例えば
は、ここに(これはNodeJSである)、サーバーのコードのようになります。
//where user is sent after authenticating through web page
server.post("/authenticated", function(req, res){
//get user iaddress from database using credentials
//(you will need the Iaddress of the user to begin a dialog)
var address = getAddressFromDB(req.body.credentials)
//then use beginDialog to start a new dialog with the user you just authenticated
//(this dialog route will only be accessible from here to guarantee authentication)
bot.beginDialog(address, "/authenticated", { userAuthToken: auth_token });
//success
res.status(200);
res.end();
});
//user is sent here from the above bot.beginDialog() call
bot.dialog("/authenticated", function(session, args){
//extract credentials (auth token) from args
var authToken = args.userAuthToken;
//use auth token here.......
});
あなたはその後、ボットダイアログエンドポイントでサポートチケットを作成して処理するために、あなたの通常のロジックを実行するでしょう。後のダイアログルートで必要な場合は、session
オブジェクト内にauthToken
を格納することもできます。 session.userData.authToken = authToken;
方法2:あなたは、あなたのユーザーを認証でき
もう一つの方法は、滝ダイアログを経由して、チャットウィンドウ自体による単純です。 しかし、これは、ユーザーが2回認証されるという問題を本当に解決することはできませんが、ユーザーが現在のWebページを離れて認証を受けなければならないという問題を解決します。
//begin user authentication here
bot.dialog("/get_username", [
function(session){
//prompt user for username here
botbuilder.Prompts.text(session, "Hello, what is your username?");
},
function(session, results){
//store username
session.userData.username = results.response;
//begin new dialogue
session.beginDialog("/get_password");
}
]);
bot.dialog("/get_password", [
function(session){
//prompt user for password here
botbuilder.Prompts.text(session, "What is your password?");
},
function(session, results){
//store password
session.userData.password = results.response;
//check credentials
if(checkCredentials(session.userData.username, session.userData.password){
//good credentials, send to post-authentication dialog
session.beginDialog("/authenticated");
} else {
//bad credentials
//reset user data and retry
session.userData.username = "";
session.userData.password = "";
session.beginDialog("/get_username");
}
}
]);
You can actually check out a working example of the above Method 2 code here.
方法3:
ウェブページを有するの好ましい方法は、連通
ボットは、資格情報を入力するプロセスを通じてユーザを導くであろう組み込みのWebChatボットは、Direct Line REST APIを介して、「バックチャンネル」を作成することができます。
WebChatコントロール(which you can download and learn about from the repo here)を使用すると、埋め込みボットとそれを収容するWebページが、定義したイベントをリッスンしてブロードキャストすることによって互いに通信できるように設定できます。
You can see a great example of this by checking out this example code that shows the client side.
While this code demonstrates what the bot & server-side code is doing behind the scenes.
あなたは、あなたのボットは、あなたのWebページから認証活性を聞くには、このメソッドを使用して、ユーザーが認証するときに、そのよう添付たい資格情報を使用してその活動を放送することができ彼らはあなたのボットで使用することができます。
こちらがお役に立てば幸いです。