Error 405 in using bot client sdk

kore-bot-sdk-client.js?v=1.0:3109 OPTIONS https://bots.kore.ai/oAuth/token/jwtgrant 405 ()

I am getting error whenever I run this index.js.

<!DOCTYPE>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=1.0">
		<script src="libs/moment.js?v=1.0" type="text/javascript"></script>
		<script src="../libs/lodash.min.js?v=1.0"></script>
		<script src='../libs/anonymousassertion.js?v=1.0'></script>
		<script src="../kore-bot-sdk-client.js?v=1.0"></script>
		<script src="chatWindow.js?v=1.0" type="text/javascript"></script>
		<script src="../libs/emoji.js" type="text/javascript"></script>
		<link href="chatWindow.css" rel="stylesheet"></link>
		<link href="../libs/emojione.sprites.css" rel="stylesheet"></link>
		<script src="../libs/recorder.js" type="text/javascript"></script>
		<script src="../libs/recorderWorker.js" type="text/javascript"></script>
		<link href="../libs/purejscarousel.css" rel="stylesheet"></link>
		<script src="../libs/purejscarousel.js" type="text/javascript"></script>
		<script src="custom/customTemplate.js" type="text/javascript"></script>
		<link href="custom/customTemplate.css" rel="stylesheet"></link>
	</head>
	<body>
		<div id="chatContainer">
		<button class="openChatWindow" id="openChatWindow">Open Chat Window</button>
		</div>
		<script type="text/javascript">
			function assertion(options, callback) {
				// Client has to fill the claims and call the callback.
				var xhr = new XMLHttpRequest();
				var _params = {
					"clientId": "cs-09c8b97f-57e5-572c-ada6-0df2dfbce8fd",
					"clientSecret": "***************************************",
					"identity": "pulkit.swami@appzlogic.com",
					"aud": "https://idproxy.kore.com/authorize",
					"isAnonymous": false
				};

				
				xhr.open('POST', 'http://demo.kore.net:3000/users/sts/');
				xhr.setRequestHeader('Content-Type', 'application/json');
				//xhr.setRequestHeader('Keep-Alive', 'Connection');
				xhr.setRequestHeader('RS256', 'alg');
				xhr.setRequestHeader('JWT', 'typ');

				xhr.onload = function() {
					console.log(xhr.status);
					if (xhr.status === 200) {
						console.log(xhr);
						var data = JSON.parse(xhr.responseText);
						console.log(data);
						options.assertion = data.jwt;
						options.handleError = koreBot.showError;
						options.botDetails = koreBot.botDetails;
						console.log(options);
						callback(null, options);
						setTimeout(function () {
							if (koreBot && koreBot.initToken) {
								koreBot.initToken(options);
							}
						}, 2000);
					} else {
						console.log(xhr);
						var data = JSON.parse(xhr.responseText);
						koreBot.showError(data);
					}
				};
				//xhr.send(_params);
				xhr.send(JSON.stringify(_params));
			}
//"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1Mjg0NTA0MzE3MzMsImV4cCI6MTUyODUzNjgzMTczMywiYXVkIjoiaHR0cHM6Ly9pZHByb3h5LmtvcmUuY29tL2F1dGhvcml6ZSIsImlzcyI6ImNzLTA5YzhiOTdmLTU3ZTUtNTcyYy1hZGE2LTBkZjJkZmJjZThmZCIsInN1YiI6InB1bGtpdC5zd2FtaUBhcHB6bG9naWMuY29tIiwiaXNBbm9ueW1vdXMiOmZhbHNlfQ.3uEZkYAum5g2SwCm0T2FESCkTNp-_BPgz0gMLqVs6cE"
			var botOptions = {};
			botOptions.logLevel = 'debug';
			botOptions.koreAPIUrl = "https://bots.kore.ai/";
			//botOptions.hitUrl = "https://demo.kore.net/api/users/sts/";
			botOptions.koreSpeechAPIUrl = "https://speech.kore.ai/";
			//botOptions.bearer = "bearer xyz-------------------";
			botOptions.ttsSocketUrl = 'wss://speech.kore.ai/tts/ws';
			botOptions.userIdentity = 'pulkit.swami@appzlogic.com';// Provide users email id here
			botOptions.recorderWorkerPath = '../libs/recorderWorker.js';
			botOptions.assertionFn = assertion;
			botOptions.koreAnonymousFn = koreAnonymousFn;
			botOptions.clientId   = "cs-09c8b97f-57e5-572c-ada6-0df2dfbce8fd"; // secure client-id
			botOptions.botInfo = {"name":"5 Minutes weather Bot","_id":"st-21e2c055-af15-59ee-bb65-74ac935dc34e"}; // bot name is case sensitive
			
			var koreBot = koreBotChat();
			var chatConfig={
				botOptions:botOptions,
				isSendButton: false,
				isTTSEnabled: true,
				isSpeechEnabled: true,
				allowLocation : true
			};
			document.getElementById('openChatWindow').addEventListener('click',function() {
				koreBot.show(chatConfig);
			});
		</script>
	</body>
</html>

Hi,
We have analyzed your index.html file and observed issue with below line
botOptions.koreAPIUrl = ā€œhttps://bots.kore.ai/ā€;

Here issue is, url is missing /api. Use below line to resolve your issue.

botOptions.koreAPIUrl = ā€œhttps://bots.kore.ai/api/ā€;

4 Likes

i am also getting error whenever run index.html

{ā€œerrorsā€:[{ā€œmsgā€:ā€œINVALID_ACCESS_TOKENā€,ā€œcodeā€:41}]} 401()

       <!DOCTYPE>
<html>
    <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=1.0">
        <script src="libs/moment.js?v=1.0" type="text/javascript"></script>
        <script src="../libs/lodash.min.js?v=1.0"></script>
        <script src='../libs/anonymousassertion.js?v=1.0'></script>
        <script src="../kore-bot-sdk-client.js?v=1.0"></script>
        <script src="chatWindow.js?v=1.0" type="text/javascript"></script>
        <script src="../libs/emoji.js" type="text/javascript"></script>
        <link href="chatWindow.css" rel="stylesheet"></link>
        <link href="../libs/emojione.sprites.css" rel="stylesheet"></link>
        <script src="../libs/recorder.js" type="text/javascript"></script>
        <script src="../libs/recorderWorker.js" type="text/javascript"></script>
        <link href="../libs/purejscarousel.css" rel="stylesheet"></link>
        <script src="../libs/purejscarousel.js" type="text/javascript"></script>
        <script src="custom/customTemplate.js" type="text/javascript"></script>
        <link href="custom/customTemplate.css" rel="stylesheet"></link>
    </head>
    <body>
        <div id="chatContainer">
        <button class="openChatWindow" id="openChatWindow">Open Chat Window</button>
        </div>
        <script type="text/javascript">
            function assertion(options, callback) {
                // Client has to fill the claims and call the callback.
                var xhr = new XMLHttpRequest();
                var _params = {
                    "clientId": "cs-0af0fb14-501e-5d7f-****-**************",
                    "clientSecret": "********************************************",
                    "identity": "raj*************@gmail.com",
                    "aud": "https://idproxy.kore.com/authorize",
                    "isAnonymous": false
                };


                

                
                xhr.open('POST', 'https://bots.kore.ai/api/users/sts/');
                xhr.setRequestHeader('Content-Type', 'application/json');
                //xhr.setRequestHeader('Keep-Alive', 'Connection');
                

                xhr.onload = function() {
                    console.log(xhr.status);
                    if (xhr.status === 200) {
                        console.log(xhr);
                        var data = JSON.parse(xhr.responseText);
                        console.log(data);
                        options.assertion = data.jwt;
                        options.handleError = koreBot.showError;
                        options.botDetails = koreBot.botDetails;
                        console.log(options);
                        callback(null, options);
                        setTimeout(function () {
                            if (koreBot && koreBot.initToken) {
                                koreBot.initToken(options);
                            }
                        }, 2000);
                    } else {
                        console.log(xhr);
                        var data = JSON.parse(xhr.responseText);
                        koreBot.showError(data);
                    }
                };
                //xhr.send(_params);
                xhr.send(JSON.stringify(_params));
            }
//"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1Mjg0NTA0MzE3MzMsImV4cCI6MTUyODUzNjgzMTczMywiYXVkIjoiaHR0cHM6Ly9pZHByb3h5LmtvcmUuY29tL2F1dGhvcml6ZSIsImlzcyI6ImNzLTA5YzhiOTdmLTU3ZTUtNTcyYy1hZGE2LTBkZjJkZmJjZThmZCIsInN1YiI6InB1bGtpdC5zd2FtaUBhcHB6bG9naWMuY29tIiwiaXNBbm9ueW1vdXMiOmZhbHNlfQ.3uEZkYAum5g2SwCm0T2FESCkTNp-_BPgz0gMLqVs6cE"
            var botOptions = {};
            botOptions.logLevel = 'debug';
            botOptions.koreAPIUrl = "https://bots.kore.ai/api/";
            //botOptions.hitUrl = "https://demo.kore.net/api/users/sts/";
            botOptions.koreSpeechAPIUrl = "https://speech.kore.ai/";
            //botOptions.bearer = "bearer xyz-------------------";
            botOptions.ttsSocketUrl = 'wss://speech.kore.ai/tts/ws';
            botOptions.userIdentity = 'raj*****@gmail.com';// Provide users email id here
            botOptions.recorderWorkerPath = '../libs/recorderWorker.js',
            botOptions.assertionFn = assertion;
            botOptions.koreAnonymousFn = koreAnonymousFn;
            botOptions.clientId   = "cs-0af0fb14-501e-5d7f-****-**********"; // secure client-id
            botOptions.botInfo = {"name":"FormulaHR","_id":"st-e03d2221-4f55-****-****-*********"}; // bot name is case sensitive
            
            var koreBot = koreBotChat();
            var chatConfig={
                botOptions:botOptions,
                isSendButton: false,
                isTTSEnabled: true,
                isSpeechEnabled: true,
                allowLocation : true
            };
            document.getElementById('openChatWindow').addEventListener('click',function() {
                koreBot.show(chatConfig);
            });
        </script>
    </body>

i am also getting error whenever run index.html

{ā€œerrorsā€:[{ā€œmsgā€:ā€œINVALID_ACCESS_TOKENā€,ā€œcodeā€:41}]}

Open Chat Window

Could you please update the JWT service endpoint to below in your index.html and give it a try?

@rajinisiva93 I assume websdk should be working fine now by making changes as suggested. Please let us know if you are still having issues.

@Subrahmanyam Thanks a lot you save my time. issue has solved.