DEV Community

Cover image for This Bot Downloads Media from any Tweet and Set Reminders for Future reference
Sojin Samuel
Sojin Samuel

Posted on • Updated on

This Bot Downloads Media from any Tweet and Set Reminders for Future reference

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

What I Built

I have been using Twitter since 2019 and have seen many valuable resources shared by people, ranging from AWS architectural patterns to SEO tips, web design principles, etc.

The highlight often is the media associated with it, which could be a representation of a diagram or a video explanation.

I often do what we've always done: bookmark it for future reference. The problem is, most of us never come back. In my case, after a couple of months, I may have even forgotten that I saved something like this.

I even wondered if it would have been great if the bookmarking feature also had some kind of reminder mechanism that I could schedule, like 'remind me next month,' etc.

Sadly, Twitter (Now X) hasn't rolled it out yet.

This is where TweetMediaManager comes to the rescue.

You can send a Tweet URL that looks something like this to the bot:
https://twitter.com/<username>/status/<id>

And later, this is what happens:

coze ai hackathon tweet media manager

But that's not just it. You could also schedule a reminder of a particular Tweet for a specific time, whether it be tomorrow, next week, or next month. That's up to you.

For example:
coze ai hackathon tweet media manager

We'll see a live demo of both of these examples in a sec 😉

I'm preparing for the AWS Solutions Architect exam, and this is going to help me a lot because there are some awesome developers on X who are sharing really valuable tips, including diagrams, gif representations of some internal processes, etc., from time to time.

Even if you're not preparing for any exams, you could still use this for many different purposes. The possibilities are endless and unique to each of you.

In my case, I used this bot to download the video where Jack Dorsey presents Twitter back in 2006. This simple video motivates me to work harder and keep going.

Demo

You can check out TweetMediaManager bot from Coze store. It's also available on Discord and Telegram.

Configuration


// prompt
# Character
You're an expert in digital content extraction specializing in obtaining multimedia materials from Twitter. Sharp, meticulous, and excellent in preserving original content quality, you shine at analysing tweets and retrieving embedded media files.

## Skills
### Skill 1: Media Extraction from Tweet URLs
- Analyze the structure and syntax of provided Tweet URLs, focusing on image or video content.
- Extract these files, maintaining their original form and quality.

### Skill 2: Secure Media Delivery 
- Following secured media extraction, use reliable and safe data transmission means to forward the obtained media files to the user.
- Ensure the unaltered, original condition receipt of these files by the user.

## Constraints
- Use the Tweet_Processor tool to extract the id from a valid Twitter URL, obtain media URLs and share these along with URL specifics like resolution based on bitrate, and the text content of the tweet.
- Stick to URLs originating from Twitter exclusively. Other platforms are not within operational limits.
- Implement ‘url_storage' to verify redundancy of the Tweet URL and save novel URLs along with their respective media URL, if any.
- Clean up the shared tweet text; remove hashtags, mentions, promotions, keep it simple, and emphasize it in bold. Also include the original tweet link and any media content.
- Guide the user towards the correct URL format if provided URLs are inconsistent with the examples:

A) https://twitter.com/<username>/status/<id>

B) https://x.com/<username>/status/<id>

- Emphasize the importance of non-commercial, personal, and ethical use of retrieved media content.
- When the media type is a video just provide the response as the text, which includes: Download URL with all obtainable resolutions you have for example define the resolution as a label based on the bit rate , Tweet text etc and do not use card data attachment on the media type video.
Enter fullscreen mode Exit fullscreen mode

Journey

Learning something new is never easy for anybody and it did took some time to get the whole Coze workflow for building an AI chatbot.

For this particular bot, none of the currently available plugins were able to bring my idea to life. So i have to build one which in this case i had to use the Twitter API v2 Tweet Lookup endpoint with some extra parameters and expansions to get the media (both image and video) from a tweet.

Unfortunately i was having a hard time to figure out how to create this custom plugin and configure it to make a call to Twitter API v2 since it required Oauth 1.0 authentication setup with Consumer key, Consumer Secret, Access Token and Access token secrets. Bearer token aren't used anymore for most cases

So i had to either drop this idea or move on with another one. which i couldn't. so i created a RestAPI on AWS APIGateway and executed a lambda function containing the programmatic logic to make a call to Twitter with Oauth 1.0 and returned a JSON comprising of the media details when a particular endpoint is accessed.

After a couple of hours of publishing TweetMediaManager i saw the users count increasing, which did made me worry and happy at the same time because to access the Tweet Lookup endpoint (to get media) i needed a Paid API plan from twitter so i choose the $100/mon plan for my use case. But the main problem was the rate limiting issue (429 error). could arise when a specific endpoint is consumed a lot more than it should on a time period (its dfferent for different API plans) of users are having a conversation at the same time or either i could go for a $5K/mon plan which does gives a lot more freedom, which i can't for this hackathon. if Coze could help, I'm definitely gonna make this plugin production ready so you can all utilize it for any number of bots.

The videos on CozeHQ official Youtube channel was very helpful for starters for building, utilizing different skills, publishing it to various channels like Telegram etc.

Most importantly the Live Stream on April 22 was really awesome, @joshalphonse and @zarazhangrui helped me to clear lot of my doubts in that available time frame. We all built a Travel Assistant bot together that day and it was such a great experience for me.

Lastly, best of luck to all contenders of Coze AI hackathon, feel free to share your projects on X with a mention to @SamuelSojin.

I'm psyched to test all of your amazing hackathon submissions.

Peace ✌️

Top comments (2)

Collapse
 
zarazhangrui profile image
Zara Zhang

Great bot!! Thanks for sharing!

Collapse
 
sojinsamuel profile image
Sojin Samuel

Appreciate it Zara