Created
September 20, 2019 04:01
-
-
Save newbold/94813c2b3d7e7c632229b59380fe635c to your computer and use it in GitHub Desktop.
Sample Watson Assistant Web Chat with custom context variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<body> | |
<script src="https://assistant-web.watsonplatform.net/loadWatsonAssistantChat.js"></script> | |
<script> | |
function preSendhandler(event) { | |
event.data.context = event.data.context || {}; | |
event.data.context.skills = event.data.context.skills || {}; | |
event.data.context.skills['main skill'] = event.data.context.skills.main_skill || {}; | |
event.data.context.skills['main skill'].user_defined = event.data.context.skills['main skill'].user_defined || {}; | |
event.data.context.skills['main skill'].user_defined.username = 'User'; | |
} | |
</script> | |
<script> | |
window.loadWatsonAssistantChat({ | |
integrationID: 'YOUR_INTEGRATION_ID', | |
region: 'YOUR_REGION' | |
}).then(function(instance){ | |
instance.on({ type: "pre:send", handler: preSendhandler }); | |
instance.render(); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment