3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LINE WORKSとObnizで遊ぼ

Last updated at Posted at 2020-12-19

LINE WORKS と Obnizで遊ぼ

LINE WORKS の API と Obniz と Node-RED で遊んでみたいと思います。

  • 本記事は完全にお遊びです。

なにをするか

Obniz に接続したボタンの押下を Node-RED で検知し、 LINE WORKS のカレンダーに自動で予定を入れます。

急な作業や MTG で自分の予定をブロックしたい時や予定表に予定を登録し忘れた際に使えるかもと無理くりユースケースを考えました。
( Obniz 使ってみたいだけだったり。。。)

使用する API , IoT 機器

LINE WORKS の API は以下を利用します。

サービス API カレンダー - 予定作成 API

Obniz には、添付のようなボタンを使用します。
(BICライターと比較するととても小さいことが分かりますね)
IMG_1261.jpg

動かしてみる

今回は、Obniz でボタンを押すと、その時間から1時間の予定を自動で挿入するようにします。
LINE WORKS に予定を入れる際には, iCalendar 形式で入れる必要があります。

動作の様子は添付から見れます。

構成

ざっくりしたものですが、構成は以下です。

スクショ.png

また、Node-RED上でのコードはこちらです。
ご自身の情報を入れればすぐ動かせるようになると思います。

コード
[{"id":"5f07fdf3.a94c54","type":"function","z":"af6ade02.80f53","name":"create request","func":"let cid = `${ msg.payload }@kazuma.com`;\nmsg.api_id = \"LINE WORKSのAPI_IDを入力\";\nmsg.service_consumer_key = \"LINE WORKSのコンシューマーキーを入力\";\nmsg.url = `https://apis.worksmobile.com/r/${ msg.api_id }/calendar/v2/users/me/calendars/defaultCalendarId/events`;\nmsg.method = \"post\";\nmsg.headers = {\n \"consumerKey\" : `${ msg.service_consumer_key }`,\n \"Authorization\" : `Bearer ${ \"LINE WORKSのアクセストークンを入力\" }`\n}\n\nlet kizyun = new Date();\n\nlet year = kizyun.getFullYear();\nlet month = kizyun.getMonth()+1;\nlet date = kizyun.getDate();\nlet hour = kizyun.getHours();\nlet minute = kizyun.getMinutes();\n\nlet start_day = `${ year }${ month }${ date }T${ hour }${ minute }00`;\n\nkizyun.setHours( kizyun.getHours() + 1 );\n\nyear = kizyun.getFullYear();\nmonth = kizyun.getMonth()+1;\ndate = kizyun.getDate();\nhour = kizyun.getHours();\nminute = kizyun.getMinutes();\n\nlet end_day = `${ year }${ month }${ date }T${ hour }${ minute }00`;\n\n\nmsg.payload ={\n \"ical\": \n`BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:LW Calendar\nCALSCALE:GREGORIAN\nBEGIN:VTIMEZONE\nTZID:Asia/Tokyo\nBEGIN:STANDARD\nDTSTART:19700101T000000\nTZNAME:GMT+09:00\nTZOFFSETFROM:+0900\nTZOFFSETTO:+0900\nEND:STANDARD\nEND:VTIMEZONE\nBEGIN:VEVENT\nSEQUENCE:0\nCLASS:PUBLIC\nTRANSP:OPAQUE\nUID:${ cid }\nDTSTART;TZID=Asia/Tokyo:${ start_day }\nDTEND;TZID=Asia/Tokyo:${ end_day }\nSUMMARY:作業\nDESCRIPTION:声かけないで\nLOCATION:家\nEND:VEVENT\nEND:VCALENDAR`\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":1040,"wires":[["baa19c83.f81ce"]]},{"id":"baa19c83.f81ce","type":"http request","z":"af6ade02.80f53","name":"->LW","method":"use","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":910,"y":1040,"wires":[["536365b5.6d7f24"]]},{"id":"536365b5.6d7f24","type":"debug","z":"af6ade02.80f53","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":1040,"wires":[]},{"id":"d7e35259.7d032","type":"uuid","z":"af6ade02.80f53","uuidVersion":"v4","namespaceType":"","namespace":"","namespaceCustom":"","name":"CalendarID生成","field":"payload","fieldType":"msg","x":540,"y":1040,"wires":[["5f07fdf3.a94c54"]]},{"id":"c0022311.7d937","type":"obniz-function","z":"af6ade02.80f53","obniz":"","name":"","code":" const button = obniz.wired(\"Keyestudio_Button\",{signal:0,vcc:1,gnd:2})\n button.onchange = (state) =>{\n if( !state ){\n node.send( msg )\n }\n }","x":340,"y":1040,"wires":[["d7e35259.7d032"]]},{"id":"61d1d91e.bfce4","type":"inject","z":"af6ade02.80f53","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":1040,"wires":[["c0022311.7d937"]]}]

最後に

今回は、LINE WORKS , Node-RED , Obniz を使って遊んでみました。
興味がある人がいれば幸いです。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?