
Create a Powerful AI-Driven News Alert System with OpenAI and Twilio! In this video, learn how to set up an AI notification system by writing a simple script that scrapes Hacker News using Puppeteer, filters relevant news about AI and software development, and sends notifications via Twilio. The tutorial walks you through the entire process, including the setup and configuration of OpenAI, Grok, Olama, and Twilio APIs. You'll also learn how to use TypeScript and bun to run the application locally. By the end, you'll have a template to build your own customized alert system. https://github.com/developersdigest/puppeteer-groq-ollama-twilio 00:00 Introduction to AI Notification Sys tem 00:03 Setting Up the Application 00:35 Configuring Notifications 00:58 Coding the Applicatio 04:38 Scraping with Puppeteer 06:16 Processing and Sending Notifications 07:40 Final Steps and Conclusion
--- type: transcript date: 2024-08-05 youtube_id: XONHV5F5XpE --- # Transcript: Web Scraping to SMS Alerts with Groq/Ollama Llama 3.1 + Twilio in this video I'm going to show you how you can set up an AI notification system what we're going to be doing is we're going to be writing a simple script we're going to be able to use open AI Gro or AMA in the example I'm going to be showing you we're going to scrape Hacker News then we're going to process the results that we take from the page we're going to determine are these results relevant to the type of news that we're interested in if they are we're going to send ourselves a text message if it is relevant news we're going to be doing that all through twilio super simple to set up otherwise we're just going to log out that there are no updates then we're just going to go through the interval again we're going to be able to use AMA Gro open AI so just to give you an idea you can run this all locally on your machine if you'd like with the exception of the tlio update now this text message piece from twio you could swap this out for just a notification on your system or an email through a provider like Amazon SCS or resend or something like that by the end of the video you'll have a good template on how to get started with all of this so in terms of the coding portion we're going to be using typescript as well as bun in terms of Frameworks we're not going to be using any in this example but I'll just go ahead and show you what this looks like if I bun index.ts what that's going to do is it's going to initiate the first run of the application then you can see it quickly goes through what it's doing behind the scenes is it's using Puppeteer to scrape Hacker News it's getting an array of all of the different results and then it's showing me the title as well as the link as well as the points I have it set up in a way for it to detect whether there are any relevant stories to AI or development and then it's going to return those back to me and this is going to be what is sent through twilio as a text message in this example I was leveraging Gro but I'm going to show you how you can do this with Ama or open AI as well once we get that response back you will see that the application is still running because we're setting up where this will just run in the background if you have it open on your computer where it's going to go and Trigger that every in this case 3 hours but you can change that out to be whatever you want or you can have this just be a onetime invocation as well in terms of the source code here you'll be able to get it within the description of the video we're going to get a few different API Keys you're going to get some free credits from toio if you want to try them out so you can go to console. too.com make an account you'll be able to grab the s number the off token as well as the twilio phone number and you can just plug them in here one by one I'm going to put a. example you can just remove the example and use that within the application then from there you can put in the phone number that you want to have this message sent to and then finally you can set up an API key for grock which it is currently free at time of recording to use or you can use the open AI API as well now if you are using AMA you don't need an API key because you're going to be running that locally the first thing that we're going to be doing is we're going to import the dependencies that we just installed so openai Puppeteer toio andv to access those environment variables that we just set up once we have that we're going to load up our environment variables once we have that set up we're going to configure all of the different interfaces that we're going to be using within our application next we're going to be setting up a configuration object within the configuration object what we're going to do is we're going to Define all of the different providers this is going to be how you can swap out the different models that you're going to be using you can swap them out here as well as where you see Gro or olama as well once we have that this is going to be where we determine what provider that we want to use for the current interval so it's set up in a way where if you want to swap out from grock to a llama you can simply do so by just swapping out this string here next we're just going to be bringing in all of the information for twilio and then finally we're going to be setting up the phone number that we're going to be passing in within our application so once we have that set up we're going to be initializing open Ai and this is going to be where we first do that lookup of the config of the particular provider that we have set within that configuration object above once that's set up we're going to be passing that into the open AI SDK and the thing to know with this isn't to be confused with open a itself this is just to Leverage The Open AI SDK and the reason that we do this is it makes it easy to swap out from one different provider to another while conforming to the same consistent open AI schema that we get as a response back as well as how we actually invoke and send a request to the endpoint we're going to call that function to actually initialize open AI once we have that set up we're going to set up our too service this is going to be where we pass in our API key and ultimately this is all that we need to actually send that SM message we're going to say where that message is from and then where that message is going and then finally we're just going to return out that the message has been sent then a similar thing here for tlio just like we had for open AI we're going to actually initialize next this is going to be the function that we use to scrape The Hacker News website now if you follow the same sort of pattern ultimately you're going to be able to scrape other websites as well so you don't necessarily need to use The Hacker News website if you want to swap in a different URL there's going to be a few different things that you can tweak the first thing that we're going to do within this function is we're going to launch Puppeteer this is going to be what we use to create a synthetic browser what Puppeteer allows you to do is it's a common tool for scraping different websites and the difference with Puppeteer is you can set up Puppeteer in a way where it will load all of the different JavaScript of the page before you actually go and parse the website you can also do a ton of other things like actually interact with the website and use it for different automations if you'd like say you want to fill out forms or go through a login process you can do that all within Puppeteer as well now if you actually want to see what the browser is doing you can set headless to false and that will actually show the Chrome instance on your screen when and it goes through the different steps if you'd like from there we're going to open up a new page then we're going to go to the website and then what we're going to do is evaluate the page based on the different selectors that are on the page this is going to be unique to the particular site that you're using in this case we're going to get an array of all of the different stories and then we're going to extract the details that we want so we're going to be getting the title element as well as the score element and then finally we're going to be getting the hrf attribute and this is going to be the payload that we ultimately send to the El LM once we have that we're going to return these stories out of our function and then finally we're going to close out the browser otherwise if there are any errors we're just going to return an empty array and then we're going to return an error within our application next this is largely going to be the portion of our application where we're leveraging an lln here we're going to be calling that function that we had just talked about and then from there we're going to be setting up a prompt within the prompt we're going to be passing in the results that we get back from Hacker News and then we're going to say scan for the stories specifically related to to AI machine learning software engineering Etc within here we have the prompt we're passing in all of the results that we got from Hacker News and then we're going to ask it to scan all of those results for stories related to AI machine learning or software engineering then we're going to say create a friendly message then what we're going to be asking to include in our text message essentially is the title a clickable link the score as well as a brief description so in this case I wanted to have it be almost like a friend texting you we're going to say keep the tone casual as if you're texting a friend and then if there are no relevant results to AI or software engineering just respond back exactly with no AI or Dev updates right now from there we're going to console log what it's doing and then this is going to be our chat completion this is going to be where we invoke the llm we're going to be passing it in within the prompt and then we're going to be using the model as well as the provider that we had declared earlier and from there if the message is longer than 50 characters we do have a message and the message doesn't equal no AI or Dev updates right now we're going to send that textt message and then finally we're just going to have a catch if we have any errors and then finally we're going to go ahead and initialize our application and that's pretty much it you can go ahead and run your application again BN index.ts and then there we have it you'll get a text message as soon as that's done that's it for this video if you found this video useful please like comment share and subscribe otherwise until the next one
Weekly deep dives on AI agents, coding tools, and building with LLMs - delivered to your inbox.
Free forever. No spam.
Subscribe FreeNew tutorials, open-source projects, and deep dives on coding agents - delivered weekly.
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.