BOCCOちゃんとあそぼう
会社でユカイ工学さんのBOCCOちゃんが置物っぽくなっていたので、活用すべくAPIを触ってみたメモ
BOCCOちゃん http://www.ux-xu.com/product/bocco
スマホのアプリをDLして簡単にBOCCOちゃんとやりとりできるけど、今回はAPIで。
アクセストークンの取得
curl -i "https://api.bocco.me/alpha/sessions" \
-d "apikey={API_KEY}" \
-d "email={email}" \
-d "password={pass}"
最初にユーザー登録をすると、API KEYがメールで送られてきます。
登録時のメールアドレスとパスワード、API KEYでアクセストークンを取得しましょう。
とれた
HTTP/1.1 200 OK
Server: Cowboy
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding
Date: Mon, 20 Feb 2017 06:39:28 GMT
Content-Length: 129
Via: 1.1 vegur
{"access_token":"{access_token}"}%
チャットルームの取得
curl -i "https://api.bocco.me/alpha/rooms/joined?access_token={access_token}"
お返事
[
{
"uuid": "{room_uid}",
"name": "BOCCOの家",
"updated_at": "2017-02-20T06:58:25Z",
"background_image": "",
"members": [
{
"user": {
"uuid": "{user_uid}",
"user_type": "human",
"nickname": "",
"icon": "",
"seller": ""
},
"joined_at": "2017-02-20T06:56:33Z",
"read_id": 1523364
},
{
"user": {
"uuid": "{room_uid}",
"user_type": "bocco",
"nickname": "BOCCO",
"icon": "",
"seller": "dmm"
},
"joined_at": "2017-02-20T06:55:04Z",
"read_id": 1523364
}
],
"messages": [],
"sensors": null
}
]
1BOCCOに対して1roomが与えられているという感じですかね。
複数BOCCOを所有している場合は、Roomがたくさん返ってくるのかな?
メッセージの送信
curl -i "https://api.bocco.me/alpha/rooms/{room_uid}/messages" \
-d "access_token={access_token}" \
-d "unique_id=`uuidgen`" \
-d "media=text" \
-d "text=こんにちはBOCCO!" \
-H "Accept-Language: ja"
おへんじ
{
"id": 1523377,
"unique_id": "0B1AE9D4-A6D5-41FE-B4DC-856891A4ADA8",
"date": "2017-02-20T07:02:59Z",
"media": "text",
"message_type": "normal",
"silent": false,
"user": {
"uuid": "{user_uid}",
"user_type": "human",
"nickname": "",
"icon": "",
"seller": ""
},
"text": "こんにちはBOCCO!",
"audio": "https://api.bocco.me/alpha/messages/xxx.ogg",
"image": "",
"sender": "{user_uid}",
"detail": null,
"dictated": false
}
メッセージの受信
curl -i "https://api.bocco.me/alpha/rooms/{room_uid}/messages?access_token={access_token}"
範囲を指定する場合
curl -i "https://api.bocco.me/alpha/rooms/{room_uid}/messages?access_token={access_token}&newer_than=1523359"
おへんじ
HTTP/1.1 200 OK
Server: Cowboy
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding
Date: Mon, 20 Feb 2017 07:07:22 GMT
Transfer-Encoding: chunked
Via: 1.1 vegur
[
{
"id": 1523353,
"unique_id": "75622616-9b3e-4a24-8109-0dca6bfd31d6",
"date": "2017-02-20T06:56:33Z",
"media": "text",
"message_type": "system.human_joined",
"silent": false,
"user": {
"uuid": "{room_uid}",
"user_type": "bocco",
"nickname": "BOCCO",
"icon": "",
"seller": "unknown"
},
"text": " joined our room. Welcome, !",
"audio": "https://api.bocco.me/alpha/messages/xxx.ogg",
"image": "",
"sender": "{room_uid}",
"detail": {
"joined_user": {
"uuid": "{user_uid}",
"user_type": "human",
"nickname": "",
"icon": "",
"seller": ""
}
},
"dictated": false
},
{
"id": 1523377,
"unique_id": "0B1AE9D4-A6D5-41FE-B4DC-856891A4ADA8",
"date": "2017-02-20T07:02:59Z",
"media": "text",
"message_type": "normal",
"silent": false,
"user": {
"uuid": "{user_uid}",
"user_type": "human",
"nickname": "",
"icon": "",
"seller": ""
},
"text": "こんにちはBOCCO!",
"audio": "https://api.bocco.me/alpha/messages/xxx.ogg",
"image": "",
"sender": "{user_uid}",
"detail": null,
"dictated": false
}
]
TTSをかなりの精度でやってくれてびっくり!モヤさまでおなじみVoiceTextでやっているそうです。
番組の印象が強すぎて片言に喋るイメージだったけど、実はすごいぞVoiceText!