Tweet Media Extractor Plugin

Tweet Media Extractor Plugin

This is a submission for the Coze AI Bot Challenge: Trailblazer.

What I Built

There are already amazing Twitter related plugins available on Coze Plugins store that can be used with Tweets.

Plugin store coze

What I needed was a plugin that could take the Media comprised in a Tweet, could be an image or video (Which I needed in different resolutions)

Tweet media extractor plugin

So I built one to use on my TweetMediaManager bot, which is an integral part for the bots functionality.

When a user submits a tweet or post URL:
https://twitter.com/<username>/status/<id>

It has a unique id associated with it. which is the input parameter being used in TweetMediaExtractor to make a LookUp search via Twitter API v2.

If the tweet does comprise media the JSON response would contain an includes field.

// Assuming the target Tweet contained a video { "data": { ... }, "includes": { "media": [ { "media_key": "77777777", "type": "video", "variants": [ { "bit_rate": 632000, "content_type": "video/mp4", "url": "https://video.twimg.com/ext_tw_video/12345678/pu/vid/avc1/320x568/4024rVUaMBVYHT_b.mp4?tag=12" }, { "bit_rate": 950000, "content_type": "video/mp4", "url": "https://video.twimg.com/ext_tw_video/12345678/pu/vid/avc1/480x852/5JGUFqyletKVFUuF.mp4?tag=12" }, { "bit_rate": 2176000, "content_type": "video/mp4", "url": "https://video.twimg.com/ext_tw_video/12345678/pu/vid/avc1/720x1280/E9zgV0hONDsfOwrq.mp4?tag=12" }, { "content_type": "application/x-mpegURL", "url": "https://video.twimg.com/ext_tw_video/12345678/pu/pl/ORE8nOl29XDVW9kz.m3u8?tag=12&container=cmaf" } ] } ], "users": [ ... ] }
}
Enter fullscreen mode
Exit fullscreen mode

Even though we could download an image by going to devtools via inspect on chrome, using the same method for a video will only give you a blob URL. which isn’t what we want. Many people do share awesome infographical or gif representation of AWS architectural patterns which is what my motivation behind building this custom plugin.

At the time of building this, I wasn’t familiar with the Coze Studio and was honestly confused like what are tools? where do they even come in action. where would I safely store my Twitter API Keys, what does Tool name mean.

Even though there is already options from Coze to bind existing external service APIs. I still needed the Studio option because I needed to implement oauth 1.0 authentication method for the Twitter API.

So my second option was to create a REST API via AWS API gateway and make a resource path /getmedia, which then executes a lambda function and the id needed was passed via query param by registering it as an Existing service (used the API Gateway REST API endpoint).

Demo

You can check out the TweetMediaExtractor plugin from Coze plugin store

Tweet Media Extractor Jason response

This is the JSON response we saw earlier, the plugin usage in action can be tested via my TweetMediaManager bot

Journey

Even though I moved forward with using API Gateway instead of Coze Studio, it was still a great experience to learn about this AWS service and made my development process much easier.

Still, I wasn’t gonna let go of using Coze Studio that easily!

It is indeed a learning process, So i created another plugin called TweetGagger (yeah another plugin powered by Twitter API) which I made it work from the Studio itself instead of using API gateway.

Read: TweetGagger Plugin Submission


Discover more from Coursity

Subscribe to get the latest posts to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *