[PYTHON] Have Siri do the job of reading AWS bills posted by Slackbot

Introduction

I've been using the iPhone for less than 10 years and noticed that Siri isn't working at all. Now that smart speakers are popular, I want my Siri to be more active, so I decided to have Slackbot read the AWS bill posted.

From the result, it looks like this. When asked about the price ... スクリーンショット 2020-01-14 22.12.01.png

He read aloud what he posted to Slack. スクリーンショット 2020-01-14 22.12.21.png Then, I will introduce various ways to make it.

Constitution

The configuration looks like this. アーキテクチャ.png

I will introduce each role.

Processing content

This time, I will focus on the ** shortcut app **. Please refer to the following articles for details on Lambda and Slackbot respectively. Lambda: (Python) Get AWS Billing Amount Slackbot: Create an echobot and notify Slack

Now let's create a shortcut. First, decide on a shortcut name. If you call Siri for the shortcut name, the registered shortcut will be executed. So this time, I will use the shortcut name "This month's charge". (I wanted to say "AWS charges", but Siri didn't understand the AWS part ...)

Next, we will define the variables used in each process.

--token: token used by SlackAPI (Legacy tokens are used this time) --channel_nm: Channel name posted by SlackAPI --channel_id: Channel ID to get the latest posts with SlackAPI --text: Text to post to Slack

Once you've set the variables, create and run the URL for your Slack Posting API. 1.png 2.png When you run the API, AWS Billing Lambda runs. It will take some time for the results to be posted to Slack, so let's wait. 3.png After waiting, we will run Slack's latest post acquisition API. Create a URL and execute the API as you did for the posting API. 4.png 5.png When you execute the latest post acquisition API, the following JSON will be returned.

{"messages":
    [{
        "bot_id":"XXXXXXXX",
        "ts":"1579095866.000200",
        "attachments":
        [{
            "color":"36a64f",
            "id":1,
            "fallback":"・ AWS Cost Explorer: 1.04 USD\n ・ Tax: 0.10 USD",
            "pretext":"The amount billed from January 01 to January 14 is 1.It's 14 USD.",
            "text":"・ AWS Cost Explorer: 1.04 USD\n ・ Tax: 0.10 USD"
        }],
        "type":"message",
        "subtype":"bot_message",
        "text":""
    }],
    "has_more":true,
    "ok":true,
    "channel_actions_ts":null,
    "channel_actions_count":0}

From here, add the value of pretext to the variable. 6.png 7.png 8.png 9.png 10.png 11.png You now have what Siri reads aloud. Transcribe the last sentence to be read into text and set the read action. 12.png done. To Siri, "Hey Siri! Let's talk!

in conclusion

Now Siri has learned one job. I think you can do more with this configuration. This time I called Slack + Lambda from the shortcut app, but I think you can do something interesting by running Python from the app Pythonista3.

Recommended Posts

Have Siri do the job of reading AWS bills posted by Slackbot
I found out by analyzing the reviews of the job change site! ??