Have you ever wanted to learn about bots, but don't know where to start? 🤖 If you're looking for a fun, safe environment to ask questions and work through various projects, demos, examples, and free Microsoft resources- this show is for you!
I'm always down for learning new things, especially if they are pointless and have the potential to annoy people, what better than building a Twitter Bot!
You can't do that with Logic Apps
First and foremost, I'm not a developer. I can write code, I frequently do, but I would in no way class myself as a Developer. I would, however, class myself as an excellent problem solver.
I'm lucky in my current role to be able to exploit that strength and be able to flex my brain working with tools and bending them to my will. One of my favourite statements is "You can't do that with X...", that to me is a challenge.
Enter @BotJurrasic, a Twitter bot built using Azure Logic Apps, Azure Table Storage, and Azure Blob Storage. I wanted to do something fun and simple as my first Twitter bot and I liked the idea of some sense of randomness in the output so I started thinking about what I could do, what tools I could use, and what would be the best way of developing and publishing the bot.
As I said, I'm not a dev, but I do regularly use things like Logic Apps as a "design first" development for a business problem. They're powerful and flexible with several built-in connectors, plus the ability to reach out to external tools such as Azure Functions, APIs, etc.
Firstly, what did I want the bot to do? Well, as anyone who works in IT knows, scope creep is real! Initially, I just wanted a bot to tweet out an update daily. Simple enough right?
Too simple screamed my brain, so off I went with the idea of tweeting out a random phrase from an array at a set interval, but each iteration of testing came with better ways to do something, more features, more bugs. AGILE!
The overall plan for the bot at the end was something like this:
- Generate a random number between 1 and 15
- If it equals 15 then go down Option B, otherwise, continue down Option A
- Option A - Tweet out a status update reading from a file in blob storage then increment that file by 1
- Option B - Tweet out an update consisting of 3 parts, each being pulled randomly from a table of potential options.
Before building out the Logic App, I wanted to make sure I had the data which the connectors would call from in place.
- For the day counter, I went with a very simple text file stored in Azure Blob Storage, from which the Logic App can read the contents (a simple number) to use in the Tweet, along with being able to update the contents of the file.
2. Storing the array of names, prefixes, and suffixes was a bit more complicated as I needed to be able to pull these back by an identifier that was randomly selected. Here I turn to our old friend, Azure Table Storage which lets you store and recall semi-structured data without needing the full overhead of a relational DB such as SQL. Very lightweight and fast, so I simply created a table for each of the required fields.
3. Last, but not least, was populating the tables with the required data. There are numerous ways to do this including the .Net library, the REST API, PowerShell, etc. but for this quick and simple use case, I've used the Azure Storage Explorer which gives you a nice clean GUI interface to all of your Blob, File Share, Queues and Tables within your Storage Accounts.
To do this, I simply uploaded a CSV containing a list of names/phrases I wanted to use along with an ID number to each respective table which gives me an output as below! Simple right?