Created
August 24, 2022 21:08
-
-
Save petitroto/710ff07730075546c07cdb6762b3dac6 to your computer and use it in GitHub Desktop.
BotpressのフックからURLをブラウザで開くサンプル
This file contains hidden or 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
// 'before incoming middleware' hook | |
if (event.preview === 'foo') { | |
const data = {url: 'http://example.com'} | |
const event2Browser = bp.IO.Event({ | |
type: 'data', | |
channel: 'web', | |
direction: 'outgoing', | |
target: event.target, | |
botId: event.botId, | |
payload: { | |
data | |
} | |
}) | |
return bp.events.sendEvent(event2Browser) | |
} |
This file contains hidden or 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> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>WebChat</title> | |
</head> | |
<body> | |
<script src="http://localhost:3000/assets/modules/channel-web/inject.js"></script> | |
<script> | |
window.botpressWebChat.init({ | |
host: 'http://localhost:3000', | |
botId: 'mybot' | |
}); | |
window.addEventListener('message', function (event) { | |
if (event.data.type === 'data') { | |
window.open(event.data.data.url) | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment