Dialogflow가 있는 CSML 챗봇에서 NLP 사용
10489 단어 dialogflowchatbotstartupcsml
단계 0.설치 프로그램
이 강좌에서 무료 Dialogflow 계정을 설정했다고 가정합니다.이 예에서, 우리는 간단한 사전 구축 에이전트'사용자 이름'을 사용할 것이다.

풍부한 채팅 로봇을 만들고 모든 통신 채널에 쉽게 배치할 수 있는 무료 CSML Studio account 가 필요하다.완료되면 빈 로봇을 만들면 방문this page하고'로봇 만들기'를 누르면 됩니다.CSML 또는 CSML Studio의 초보자라면 먼저 읽어보시기 바랍니다Getting Started!
1단계.Dialogflow 및 CSML Studio 연결
채팅 로봇을 Dialogflow 에이전트와 연결하려면 먼저 Dialogflow 서비스 계정 키를 가져와야 합니다.
단계 2.CSML 챗봇에서 Dialogflow NLP 사용
자연 언어 처리는 CSML 채팅 로봇에서 몇 가지 다른 방식으로 사용할 수 있다. 즉, 의도를 수평으로 흐름과 일치하게 하거나 수직으로 흐름 속에서 진행할 수 있다.의도와 흐름에 맞는 것부터 시작합시다.
트리거
CSML 흐름은 * 명령으로 트리거됨*명령을 찾으면 다른 행위보다 적절한 흐름이 시작됩니다.스트림을 시작하려는 경우 스트림 명령에 이름을 추가해야 합니다.이것은 흐름의 설정에서 완성할 수 있다.

이 예에서 우리는
GetUsername
라는 흐름을 만들고 명령을 name.user.get
로 설정합니다.만약 사용자가 "내 이름이 무엇입니까?"라고 말한다면,요청은 Dialogflow에 전송되어 분석됩니다. Dialogflow는 intentname.user.get
와 일치하는 결과를 되돌려주고 CSML 엔진에서 flowGetUsername
의 시작 절차를 터치하여 이전에 열린 대화를 닫습니다.내부 흐름
전송된 사용자 이벤트와 일치하도록 흐름에서 Dialogflow를 사용할 수도 있습니다.예를 들어 이 장면에서 로봇은 사용자에게 자신의 사용자 이름을 좋아하는지 물어보고 그들에게 두 개의 단추를 표시한다.

이 단계에서 사용자는 그 중의 단추를 사용할 수 있지만, 그들은'나는 나의 이름을 매우 좋아한다'는 내용을 입력할 수 있으며, 우리는 그 중의 단추와 일치하기를 희망한다.이것은 매우 쉽다!이미 두 가지 의도
name.user.feedback.good
와 name.user.feedback.bad
가 있다.의도 이름을 해당 버튼 accepts
매개변수에 간단히 추가하고 사용자 입력과 일치시킬 수 있습니다. say Question(
"Do you like your name?",
button_type="quick_reply",
buttons=[
Button("Yay!", accepts=["name.user.feedback.good"]) as btny,
Button("Meh...", accepts=["name.user.feedback.bad"]) as btnn,
]
)
hold
if (event.match(btny)) {
say "I'm glad you like it!"
goto end
}
else if (event.match(btnn)) {
say "Oh, I'm sorry to hear that!"
goto end
}
else {
say "I'm sorry, I didn't get that."
goto feedback
}
흐름 내 일치 의도현재 사용자의 말이
name.user.feedback.good
로 해석되면 로봇은 사용자가 Yay!
버튼을 누르는 것처럼 반응한다.
실체
제가 보여드리고 싶은 마지막 팁은 CSML에서 에이전트의 * 실체*를 사용할 수 있다는 것입니다!
이 장면에서 사용자가 그들의 이름을 바꾸려고 하는 장면을 상상해 봅시다.그들은 지금 나를 존이라고 부른다고 말할 것이다.이 말은 Dialogflow의
name.user.save
의도와 일치하지만 given-name
실체도 "John"
로 설정됩니다.
우리 로봇에서 그것을 사용하자.이름 변경 요청
name.user.save
을 처리하기 위해 새 흐름을 만들고 NLP로 트리거하려고 합니다.이벤트의 컨텐트를
say "{{event.get_content()}}"
로 인쇄하려고 하면 대량의 정보가 포함된 큰 객체가 표시됩니다.{
"payload": "name.user.change",
"text": "I want to change my name to John",
"_nlp_provider": {
"provider": "dialogflow",
"project_id": "user-name-hetw"
},
"_original_event": {
"content_type": "text",
"content": {
"text": "I want to change my name to John"
}
},
"_nlp_result": {
"allRequiredParamsPresent": true,
"queryText": "I want to change my name to John",
"intent": {
"inputContextNames": [],
"name": "projects/user-name-hetw/agent/intents/5d1759cb-6eb1-4cec-bde2-d7391c9a932d",
"trainingPhrases": [],
"followupIntentInfo": [],
"displayName": "name.user.change",
"parentFollowupIntentName": "",
"messages": [],
"rootFollowupIntentName": "",
"mlDisabled": false,
"outputContexts": [],
"defaultResponsePlatforms": [],
"parameters": [],
"events": [],
"priority": 0,
"action": "",
"resetContexts": false,
"webhookState": "WEBHOOK_STATE_UNSPECIFIED",
"isFallback": false
},
"speechRecognitionConfidence": 0,
"languageCode": "en",
"fulfillmentMessages": [
{
"message": "text",
"platform": "PLATFORM_UNSPECIFIED",
"text": {
"text": [
""
]
}
}
],
"webhookPayload": null,
"action": "name.user.change",
"intentDetectionConfidence": 1,
"fulfillmentText": "",
"webhookSource": "",
"parameters": {
"fields": {
"last-name": {
"stringValue": "",
"kind": "stringValue"
},
"nick-name": {
"stringValue": "",
"kind": "stringValue"
},
"given-name": {
"stringValue": "John",
"kind": "stringValue"
},
"type": {
"kind": "stringValue",
"stringValue": ""
}
}
},
"sentimentAnalysisResult": null,
"outputContexts": [],
"diagnosticInfo": null
}
}
event._nlp_result
키는 모든 내용을 포함하고 있습니다. 예를 들어 returned by Dialogflow's API (이 링크를 누르면 이런 방식으로 검색할 수 있는 모든 데이터를 볼 수 있습니다.)실제로 이러한 방식으로 실체에 접근할 수 있습니다. 실제로 event._nlp_result.parameters.fields
은 이 목적에 사용할 수 있는 모든 가능한 실체를 포함하고 있습니다. 우리의 예시에서 볼 수 있듯이 given-name
실체는 "John"
로 설정되어 있습니다.전송 의도에서 이름과 관련된 모든 엔티티를 추출하는 작은 함수를 만듭니다.
fn getNameEntity(event):
do entities = event._nlp_result.parameters.fields
if (entities) {
if (entities["given-name"].stringValue) return entities["given-name"].stringValue
if (entities["last-name"].stringValue) return entities["last-name"].stringValue
if (entities["nick-name"].stringValue) return entities["nick-name"].stringValue
}
return Null
현재 사용자가 "내 이름을 John으로 설정하고 싶다"고 말하면, 우리는 그들이 설정하고자 하는 이름의 값을 직접 검사하고, 간단한 예/아니오를 통해 직접 설정을 확인할 수 있지만, 만약 그들이 우리에게 이름을 주지 않았다면, 우리는 먼저 그들의 이름을 물어봐야 한다.start:
// We know that the matched intent for this flow requires us to change the user's name,
// but we need to check if the event triggering this flow has one of the `name` entities set
remember newname = getNameEntity(event)
// The user did not give us their new name, we need to specifically ask for it
if (!newname) goto askForNameInput
// Otherwise we can just ask for confirmation that we understood it right
// and skip the "what's your new name" part
goto confirmNewName
과연 다음은 이번 대화의 결과다.
결론
보시다시피 기존 Dialogflow 에이전트를 CSML Studio와 함께 사용하는 것은 매우 간단합니다.이렇게 통합된 설정은 1분도 걸리지 않아 이 두 플랫폼의 대화 구축 장점을 쉽게 얻을 수 있습니다. CSML을 사용하면 풍부한 대화를 쉽게 구축할 수 있습니다. 텍스트뿐만 아니라 이미지, 동영상, 회전목마도 사용할 수 있습니다.내장 응용 프로그램이나 프로그래밍 언어의 함수를 사용하여 모든 API나 서비스에 연결하고 Dialogflow의 강력한 NLU를 사용하여 채팅 로봇의 이해 기능을 향상시킵니다!
이 강좌에서 우리는 단지 Dialogflow와 CSML을 사용하여 실현할 수 있는 기능을 간단하게 소개하고 CSML Studio의 이 감동적인 기능을 간략하게 소개하였다.위에서 보여준 채팅 로봇의 전체 소스 코드is available on github.너도 import it on CSML Studio in just one click 빨리 입문할 수 있어!
다음 CSML 프로젝트에서 Dialogflow를 충분히 활용할 수 있을 것으로 믿습니다!
Reference
이 문제에 관하여(Dialogflow가 있는 CSML 챗봇에서 NLP 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/bastienbot/using-nlp-in-a-csml-chatbot-with-dialogflow-43da텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)