NaverWorks bot

이석준·2022년 5월 17일
0

0. naverWorks??

매장이나 점포에서 근무정보, 본사와 소통, 불만 고객 대처 등의 업무를 처리하기 위한 platform이다.
서비스중 bot 이라는 서비스로 bot을 추가하여 여러 user와 소통해보자.

1. 계정 생성

https://naver.worksmobile.com/pricing/

2. app, Bot 추가

https://developers.worksmobile.com/kr/console/openapi/v2/app/detail/view/WhJWnFICAY4zYfDNmbWfVQ

API 2.0 App -- RedirectURL : 인증 요청시 인가값을 받기위한 URL , param으로 code가 전송됩니다.

code는 token 값을 발급 받기 위해 사용됩니다.

Bot 생성 후 Callback URL은 Bot에서 Message callback에 사용됩니다.

3. 인가 코드 요청

GET https://auth.worksmobile.com/oauth2/v2.0/authorize?

client_id={Client ID}

&redirect_uri={decode Redirect URL}

&scope=bot

&response_type=code

&state=200

&isRefreshed=true

ClientId , Redirect URL은 Developer Console에서 확인 가능합니다.

4. 토큰 발급

POST https://auth.worksmobile.com/oauth2/v2.0/token?

code ={Redirect URL로 들어온 request 값}

&grant_type=authorization_code

&client_id={Client ID}

&client_secret={Client Secret}

client_secret은 Developer Console에서 확인 가능합니다.

5. message 전송

URL

- POST https://www.worksapis.com/v1.0/bots/{bot_ID}/channels/{channel_ID}/messages
- POST https://www.worksapis.com/v1.0/bots/{bot_ID}/users/{user_ID}/messages
body

```
{   "content": {     "type": "text",     "text": "안녕하세요."    } }
```

Header

  {“Authorization”  : “Bearer {token}“ , “Content-Type“ : “application/json“}

botID는 Developer Console bot에서 확인할 수 있습니다.

user_ID 및 channelID는 callback의 source항목 값을 이용해 알 수 있습니다.

 {
"type":"message"
,"source":
   {
      "userId"={user_ID}
      ,"channelId"={channelID}
      ,"domainId"={domainID}
   }
, "issuedTime"="2022-05-16T07:57:07.827Z"
, "content"={type"="text", "text"="메세지내용"}
}

source에서 channel_ID가 있는 경우 1:1 채팅이 아닌 그룹 채팅을 의미 하는 것으로 보입니다.
content는 메세지의 타입에 따라 다르게 표현됩니다.
메시지 공통 속성 - Bot -
https://developers.worksmobile.com/kr/reference/bot-send-content?lang=ko

6. callback

Developer Console에서 변경 가능 하며 SSL 적용이 되어야 사용됩니다.

현재 443 port 적용하여 테스트 완료했습니다.

7. 정리

NAVER WORKS에서 token 발급 받아 message 발신, 수신 할 수 있다..

kakaoAPI나 works 1.0의 경우 senderKey로 처리하는데, token은 만료되기 때문에 발신을 위한 Bearer token은 주기적으로 발급 받아 사용해야 한다.

0개의 댓글