――I had the opportunity to summarize the Slack Bot that I created using AWS Lambda before, so I thought I'd post it to Qiita including a memorandum. ――The memory at the time of creation has faded, but I hope it will be helpful to anyone, such as where they got caught in the range they remember.
――The author's house is located between stations on multiple lines, and it was difficult to move from one station to another. ――It was difficult to take the option of taking another line (moving the station) even if you noticed a delay after arriving at the station. ――It would be nice if you could check the route information yourself when you wake up, but in the morning hours, it was often fluttering, and there were many days when I missed it. ――I felt that it would be convenient if notifications came to the tools (LINE and Slack) that I usually check and let me know. ――I'm genuinely interested in making something with Lambda (including FaaS and SaaS), so I decided to make it myself. -(One of the reasons is that I wanted to program after a long time because I didn't code the occupational pattern at that time.)
――I want you to be notified automatically if the train is delayed between the time you wake up in the morning and before you get on the train. --Monday-Friday morning 7-9am --Notification destination is the channel specified by Slack
--I wrote it with draw.io (https://www.draw.io/). --The language I was using is Python 3.x.
--AWS Lambda: AWS service that can execute event-driven (runs triggered by something (= event)) application - https://aws.amazon.com/jp/lambda/ --Amazon CloudWatch: Resource and application monitoring / management service --This time, I used CloudWatch Event (a function to distribute events to targets (Lambda etc.) based on specific rules). - https://aws.amazon.com/jp/cloudwatch/ --Scraping: Technology that extracts information from information obtained from websites using HTML tags --This time, I used "Beautiul Soup" which is one of Python's scraping libraries. - https://www.crummy.com/software/BeautifulSoup/bs4/doc/ --Slack Incoming Webhooks: Add-ons (like) that post specified messages to specific channels using HTTP requests ――The specifications have changed from when you created it, and it seems that you can add Incoming Webhooks to the created Slack application. - https://api.slack.com/messaging/webhooks
――It looks like the image below. (It will check and notify you every 10 minutes.)
――I was able to solve the problem at first. ――By receiving the morning notification, you can now select a route (station) that is not delayed. ――I started thinking that it would be nice to be notified when the delay was resolved. ――Currently, it is a specification to judge that the delay has been resolved by not receiving notifications. ――I felt that it would be convenient to make various bots other than this. --Shopping notes, today's schedule (arrival of luggage, etc.) ...
――When I thought that the timing of notification was wrong, the time specified was UTC. ――It was necessary to add 9:00 to fix it to Japan time. --Lambda timed out as a result of the information acquisition & scraping process taking a long time. --Lambda's default timeout is 3 seconds, so it looks like you'll need to change it if necessary. (It was possible to change it later with the GUI.)
Recommended Posts