Bluemix+Node-RED에서 Watson QA
【주의】Watson QA 서비스는 2015년 12월 16일로 제공 종료되었습니다.
Node-RED 이라고 하면 간단하게 센서 데이터 수집을 하기 위한 툴이라는 측면이 강합니다만, Bluemix 에서는 Watson 관련 노드도 공개되고 있습니다. 이번에는 트위터 봇을 입출력 장치로 Watson에 문의하는 샘플을 만들었습니다.
전제
Node-RED 애플리케이션 만들기
Bluemix에서 응용 프로그램을 만듭니다. (여기서는 nrqasample이라는 이름으로하고 있기 때문에 URL은 nrqasample.mybluemix.net입니다)
보일러 플레이트 “Node-RED Starter”를 선택합니다.

그대로 어플리케이션의 스테이징을 실시합니다.

스테이징이 끝나면 브라우저에서 애플리케이션(이번에는 nrqasample.mybluemix.net)을 엽니다. 그러면 플로우 편집기가 나타납니다.

대시보드는 이러한 구성으로 되어 있습니다. Node-RED Starter 보일러 플레이트를 선택하면 Cloudant NoSQL DB 서비스와 Monitoring and Analytics 서비스가 각각 자동으로 추가됨을 알 수 있습니다.

이대로 누구나 플로우 에디터에 액세스 할 수 있으므로 사용자 이름과 암호를 설정합시다. 대시보드에서 사용자 환경 변수를 설정하기만 하면 됩니다.

환경 변수를 설정한 후 플로우 에디터에 다시 액세스하면 로그인이 요청됩니다.

흐름 만들기
이제 흐름을 만들겠습니다.
먼저 Watson Q&A를 활용하기 위해 대시보드에서 서비스를 추가합니다.

그런 다음 흐름 편집기에서 흐름을 만듭니다.

각 노드의 유형과 설정은 다음과 같습니다.
이름
유형
용도 및 설정
Mention

멘션의 취득·Log in as: @bot 계정·Search: all public tweets·for: "@bot 계정"※ 취득하는 tweet의 조건(선두 캐릭터 라인)·Name: "Mention"
품질보증

Watson QA 문의 · Name: "QA"· Corpus: Travel · Output: Top answer
Cut

140자로의 정형·Name: "Cut"·Function:(*1)·Outputs: 1
Reply

Tweet출력·Twitter: @계정·Name: "Reply"
Debug

Debug 메시지 출력 ·Output: message property, msg."payload"·to: debug tab·Name: "Debug"
(*1) "Cut"노드 코드
var sender = msg.topic.replace(/^tweets\//, '')
if (msg.payload.length + sender.length + 2 > 140) {
msg.payload = '@' + sender + ' ' + msg.payload.substring(0, 140 - sender.length - 6) + " ..."
} else {
msg.payload = '@' + sender + ' ' + msg.payload
}
return msg;
실행
플로우 편집기의 오른쪽 상단에 있는 deploy 버튼을 누르면 최신 배포가 수행됩니다. 단, 트위터 api의 사양상 15분에 한번밖에 갱신할 수 없는 경우가 있으므로 주의해 주세요.

그럼 멘션을 보내 봅시다. (이 예에서는 @travelqabot이라는 계정 이름의 봇을 사용합니다.)

응답이 왔습니다.

디버그 노드에도 로그가 있습니다.

요약
Reference
이 문제에 관하여(Bluemix+Node-RED에서 Watson QA), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/mkyutani/items/4e9b9cbde75dae49963f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)