์ด๋ฒ ํตํฉ์ ์น์ฌ์ดํธ์ ์ฝ์ ํ ์ ์๋ ๋ง์ถค์ค์ ๊ฐ๋ฅํ ์์ด์ ํธ์ฉ ์ฑํ ๋ํ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ค์
์ด ํตํฉ์ ์ธ์ฆ๋๊ฑฐ๋ ์ธ์ฆ๋์ง ์์ ์ต์ข ์ฌ์ฉ์ ์์ด์ ํธ ์ฟผ๋ฆฌ ์ก์ธ์ค๋ฅผ ํ์ฉํ ์ ์์ต๋๋ค.
์ธ์ฆ๋์ง ์์ ์ค์
Dialogflow CX ๋ฉ์ ์ ์์ด์ ํธ์ ๋ฌด๋จ ์ก์ธ์ค๋ฅผ ์ค์ ํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
- Dialogflow CX ์ฝ์๋ก ์ด๋ํฉ๋๋ค.
- Google Cloud ํ๋ก์ ํธ๋ฅผ ์ ํํฉ๋๋ค.
- ์์ด์ ํธ๋ฅผ ์ ํํฉ๋๋ค.
- ๊ด๋ฆฌ ํญ์ ์ ํํฉ๋๋ค.
- ์ผ์ชฝ ์ฌ์ด๋๋ฐ ๋ฉ๋ด์์ ํตํฉ์ ํด๋ฆญํฉ๋๋ค.
- Dialogflow CX ๋ฉ์ ์ ์์ ์ฐ๊ฒฐ์ ํด๋ฆญํฉ๋๋ค.
- ๊ตฌ์ฑ ๋ํ์์๊ฐ ์ด๋ฆฝ๋๋ค.
- ์ด์ ์ ์ด ์์ด์ ํธ์ ๋ํ ํตํฉ์ ์ค์ ํ ๊ฒฝ์ฐ ์ฝ์ ๊ฐ๋ฅํ HTML ์ฝ๋๊ฐ ํ์๋ฉ๋๋ค. ์ธ์ฆ ์ฌ๋ถ์ ๊ด๊ณ์์ด ๋ํ์์ ํ๋จ์์ ์ฌ์ฉ ์ค์ง... ๋ฒํผ์ ํด๋ฆญํ์ฌ ๋ค์ ๋จ๊ณ์์ ์ค์ ์ ๋ค์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
- ํ๊ฒฝ์ ์ ํํฉ๋๋ค.
- ์ธ์ฆ๋์ง ์์ API๋ฅผ ์ ํํฉ๋๋ค.
- ์คํ์ผ์ ์ ํํฉ๋๋ค.
- ์ํ๋ ๊ฒฝ์ฐ ๋๋ฉ์ธ ์ก์ธ์ค๋ฅผ ์ ํํฉ๋๋ค.
- ์ธ์ฆ๋์ง ์์ API ์ฌ์ฉ ์ค์ ์ ํด๋ฆญํฉ๋๋ค.
- ๋ํ์์์ ์น์ฌ์ดํธ์ ์ฝ์ ํ ์ ์๋ ์ฝ์ ๊ฐ๋ฅํ HTML ์ฝ๋๊ฐ ํ์๋ฉ๋๋ค. ์ด ์ฝ๋๋ฅผ ๋ณต์ฌํฉ๋๋ค.
- ์๋ฃ๋ฅผ ํด๋ฆญํฉ๋๋ค.
์ธ์ฆ๋ ์ค์
Dialogflow CX ๋ฉ์ ์ ์์ด์ ํธ์ ์ธ์ฆ๋ ์ก์ธ์ค๋ฅผ ์ค์ ํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
- Dialogflow CX ์ฝ์๋ก ์ด๋ํฉ๋๋ค.
- Google Cloud ํ๋ก์ ํธ๋ฅผ ์ ํํฉ๋๋ค.
- ์์ด์ ํธ๋ฅผ ์ ํํฉ๋๋ค.
- ๊ด๋ฆฌ ํญ์ ์ ํํฉ๋๋ค.
- ์ผ์ชฝ ์ฌ์ด๋๋ฐ ๋ฉ๋ด์์ ํตํฉ์ ํด๋ฆญํฉ๋๋ค.
- Dialogflow CX ๋ฉ์ ์ ์์ ์ฐ๊ฒฐ์ ํด๋ฆญํฉ๋๋ค.
- ๊ตฌ์ฑ ๋ํ์์๊ฐ ์ด๋ฆฝ๋๋ค.
- ์ด์ ์ ์ด ์์ด์ ํธ์ ๋ํ ํตํฉ์ ์ค์ ํ ๊ฒฝ์ฐ ์ฝ์ ๊ฐ๋ฅํ HTML ์ฝ๋๊ฐ ํ์๋ฉ๋๋ค. ์ธ์ฆ ์ฌ๋ถ์ ๊ด๊ณ์์ด ๋ํ์์ ํ๋จ์์ ์ฌ์ฉ ์ค์ง... ๋ฒํผ์ ํด๋ฆญํ์ฌ ๋ค์ ๋จ๊ณ์์ ์ค์ ์ ๋ค์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
- ํ๊ฒฝ์ ์ ํํฉ๋๋ค.
- ์น์ธ๋ API๋ฅผ ์ ํํฉ๋๋ค.
- ์คํ์ผ์ ์ ํํฉ๋๋ค.
- ์ํ๋ ๊ฒฝ์ฐ ๋๋ฉ์ธ ์ก์ธ์ค๋ฅผ ์ ํํฉ๋๋ค.
- ์น์ธ๋ API ์ฌ์ฉ ์ค์ ์ ํด๋ฆญํฉ๋๋ค.
- ๋ํ์์์ ์น์ฌ์ดํธ์ ์ฝ์ ํ ์ ์๋ ์ฝ์ ๊ฐ๋ฅํ HTML ์ฝ๋๊ฐ ํ์๋ฉ๋๋ค. ์ด ์ฝ๋๋ฅผ ๋ณต์ฌํฉ๋๋ค.
- ์๋ฃ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- OAuth ํด๋ผ์ด์ธํธ๋ฅผ ์ค์ ํฉ๋๋ค.
- ์กฐ์ง์ OAuth ๋์ ํ๋ฉด์ ๋ง๋ญ๋๋ค.
ํ์ ๋ฒ์๋ก
https://www.googleapis.com/auth/cloud-platform
์ ์ถ๊ฐํฉ๋๋ค. - OAuth 2.0 ํด๋ผ์ด์ธํธ ID๋ฅผ ๋ง๋ญ๋๋ค.
์น์ธ๋ JavaScript ์ถ์ฒ์์ ์์ด์ ํธ๋ฅผ ํธ์คํ
ํ๊ณ ์ฟผ๋ฆฌํ ์ ์๋ HTTP ์ถ์ฒ๋ฅผ ์ง์ ํฉ๋๋ค.
์๋ฅผ ๋ค๋ฉด
https://your-company.com
์ ๋๋ค. - ์ต์ข ์ฌ์ฉ์์๊ฒ ์์ด์ ํธ๋ฅผ ์ฟผ๋ฆฌํ ์ ์๋ ๊ถํ์ ์ ๊ณตํฉ๋๋ค. ๊ฐ ์ต์ข ์ฌ์ฉ์ ๋๋๊ทธ๋ฃน์ Dialogflow API ํด๋ผ์ด์ธํธ ๋ฐ ์๋น์ค ์ฌ์ฉ๋ ์๋น์ ์ญํ ์ด ์๋ ์ฃผ ๊ตฌ์ฑ์์ผ๋ก ์ถ๊ฐํฉ๋๋ค.
- ์กฐ์ง์ OAuth ๋์ ํ๋ฉด์ ๋ง๋ญ๋๋ค.
ํ์ ๋ฒ์๋ก
์ฝ์
์์์ ๋ณต์ฌํ ์ฝ์
์ฝ๋๋ฅผ ์น์ฌ์ดํธ์ ์นํ์ด์ง์ ๋ถ์ฌ๋ฃ์ต๋๋ค.
<script>
๋ฐ <df-messenger>
HTML ์์๋ ํ์ด์ง์ <body>
์์์ ์์ด์ผ ํฉ๋๋ค.
์ธ์ฆ๋ ํตํฉ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ <df-messenger>
์ oauth-client-id
์์ฑ์ Oauth ํด๋ผ์ด์ธํธ ID๋ก ์ค์ ํฉ๋๋ค. ๋๊ตฌ ์ธ์ฆ์ ์ต์ข
์ฌ์ฉ์์ ID๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ์ํ๋ ์ด๋ฆ์ผ๋ก access-token-name
์์ฑ์ ์ค์ ํ์ธ์.
๊ทธ๋ฐ ๋ค์ ๋๊ตฌ ์ธ์ฆ์ ๊ฐ์ด $session.params.ACCESS_TOKEN_NAME
์ธ Bearer ํ ํฐ์ ์ฌ์ฉํฉ๋๋ค.
์ ๋ฐ์ดํธ๊ฐ ํ์ํ ๋ค๋ฅธ ๋ชจ๋ ์์ฑ์ ์ ๋ฐ์ดํธํฉ๋๋ค.
๋ฐ์ํ ๋ ์ด์์์ ํ์ฉํ๋ ค๋ฉด <head>
์์์ ๋ค์์ ์ถ๊ฐํฉ๋๋ค.
<meta name="viewport" content="width=device-width, initial-scale=1">
๋ง์ถค์ค์
์ฑํ ๋ํ์์์ ๋ชจ์๊ณผ ๋์์ ์ํฅ์ ์ฃผ๊ธฐ ์ํด ์ ์ฉํ ์ ์๋ ๋ค์ํ HTML ๋ง์ถค์ค์ ๋ฐ CSS ๋ง์ถค์ค์ ์ด ์์ต๋๋ค.
JavaScript
์ฑํ ๋ํ์์์ ์ํธ์์ฉํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ์ฌ๋ฌ JavaScript ์ด๋ฒคํธ ๋ฐ JavaScript ํจ์๊ฐ ์์ต๋๋ค.
์
๋ค์ ์์๋ HTML ๋ง์ถค์ค์ , CSS ๋ง์ถค์ค์ , JavaScript ์ด๋ฒคํธ ์ฒ๋ฆฌ๋ฅผ ๋ณด์ฌ์ค๋๋ค.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>My chat</title>
<style>
df-messenger {
/*
* Customize as required. df-messenger will fill the
* space that is provided.
*/
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 320px;
}
</style>
<script src="https://www.gstatic.com/dialogflow-console/fast/df-messenger/prod/v1/df-messenger.js"></script>
</head>
<body>
<df-messenger
location="global" <!-- TODO: update agent location as needed -->
project-id="my-project-id" <!-- TODO: update project ID -->
agent-id="my-agent-id" <!-- TODO: update agent ID -->
language-code="en" <!-- TODO: update agent language as needed -->
>
<df-messenger-chat
chat-title="Agent Name" <!-- TODO: update dialog title as needed -->
></df-messenger-chat>
</df-messenger>
<script>
// An example of handling events: Navigate to the first suggested URL.
document.addEventListener('df-url-suggested', (event) => {
if (Array.isArray(event.detail.suggestedUrls) &&
event.detail.suggestedUrls.length) {
window.location.href = event.detail.suggestedUrls[0];
}
});
</script>
</body>
</html>
Fulfillment
์๋ด์ฌ ์๋ต์ ์ฌ์ฉํ ์ ์๋ ๋ค์ํ fulfillment response types์ด ์์ต๋๋ค.
์๋ต ํผ๋๋ฐฑ
๋ง์ฝ ์๋ต ํผ๋๋ฐฑ์ด ์ฌ์ฉ ์ค์ ๋์ด ์์ผ๋ฉด, ์ฑํ ๋ํ์์์ ์ข์์ ๋ฐ ์ซ์ด์ ๋ฒํผ์ด ์ฌ์ฉ์ ์ธํฐํ์ด์ค์ ๊ธฐ๋ณธ์ผ๋ก ์ถ๊ฐ๋ฉ๋๋ค. ๋ํ ์ค ์ต์ข ์ฌ์ฉ์๊ฐ ์ด ๋ฒํผ์ ํด๋ฆญํ์ฌ ์์ด์ ํธ ์๋ต์ ๋ํ ํผ๋๋ฐฑ์ ์ ๊ณตํ ์ ์์ต๋๋ค. ์ฌ์ฉ์๊ฐ ์ซ์ด์๋ฅผ ์ ํํ ๋๋ ๋ถ์ ์ ์ธ ์๊ฒฌ์ ๋ณด๋ด๋ ์ด์ ๋ฅผ ์ ํ์ ์ผ๋ก ์ ๊ณตํ ์ ์์ต๋๋ค.
์ปค์คํ ํผ๋๋ฐฑ ๊ตฌ์ฑ์์
์ปค์คํ
ํผ๋๋ฐฑ ์์๋ฅผ ์ง์ ํ๋ ค๋ฉด ์น์ฌ์ดํธ์ ์ ์ปค์คํ
์์๋ฅผ ์ ์ํด์ผ ํฉ๋๋ค.
ํผ๋๋ฐฑ์ ์ ์ถํ๋ ค๋ฉด ์์๊ฐ df-custom-submit-feedback-clicked
์ด๋ฒคํธ๋ฅผ ๋ด๋ณด๋ด์ผ ํฉ๋๋ค. ํฌํจ๋ detail
ํ๋๋ ๋ฌธ์์ด์ด์ด์ผ ํฉ๋๋ค.
class CustomFeedbackElement extends HTMLElement {
constructor() {
super();
// It is not strictly required but recommended to contain the custom
// element in a shadow root.
this.renderRoot = this.attachShadow({mode: 'open'});
}
// Web component Lifecycle method.
connectedCallback() {
const wrapper = document.createElement('div');
// Build the component as required.
const button = document.createElement('button');
button.innerText = 'Submit';
button.addEventListener('click', () => {
this._onSubmitClick();
});
wrapper.appendChild(button);
this.renderRoot.appendChild(wrapper);
}
// Called when Submit button is clicked.
_onSubmitClick() {
const event = new CustomEvent("df-custom-submit-feedback-clicked", {
// `detail` may be any string,
// this will be sent to the backend to be stored.
detail: JSON.stringify({
"usefulness": 2,
"accuracy": 3,
}),
// Required to propagate up the DOM tree
// https://developer.mozilla.org/en-US/docs/Web/API/Event/bubbles
bubbles: true,
// Required to propagate across ShadowDOM
// https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
composed: true,
});
this.dispatchEvent(event);
}
}
(function() {
// Registers the element. This name must be "df-external-custom-feedback".
customElements.define('df-external-custom-feedback', CustomFeedbackElement);
})();
๋๋ฒ๊น
Dialogflow ๋ฉ์ ์ ๋ก ์์ด์ ํธ๋ฅผ ๋ก์ปฌ์์ ํ ์คํธํ๋ ค๋ฉด ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
- ์ ์ค๋ช ์ฒ๋ผ ํ์ด์ง์ Dialogflow ๋ฉ์ ์ ์์๋ฅผ ์ฝ์ ํฉ๋๋ค.
- ํน์ ํฌํธ๋ก ํ์ด์ง์ ๋ก์ปฌ HTTP ์๋ฒ๋ฅผ ์์ํฉ๋๋ค.
http://localhost:port_number
์์ ํ์ด์ง์ ์ก์ธ์คํฉ๋๋ค.