There's a lot of promises around this, but of course it is simpler than you expected. And now let's see the code for this to work. So let's start first with the content script. The content script, at the end... Sorry for this mess, but yeah. So at the end, it has a component where we added the basic action that we are executing, and every time we click on the action, it will show the result, but also if we click on the sparklers, that is just the star, it will generate this AI. So this is the method we are calling and where we are sending the message to background. Here I said, okay, send the message, get AI response with the action type, so basically the description, the usage, everything that we set in preferences, and the text selection from the user. And then the background is the one that should receive this message.
So if we go to the background, to the index file, we will see we have an onMessageListener. This onMessageListener is just getting this information that we sent, and then if the action is what is expected, it will call a method that will select which API we want to use. So here, based on action type, if it's translate, we will go to the translator API. If not, we will use the user summarizer. And if it's any other action, we will use the prompt API that is just a session like a chat.
Just to let you know, to finish the talk, you need to understand that every time you create our extension, it doesn't mean it will go to production. It can be local for yourself, you can open source it, and everyone can download it to use it. So you can make it available without actually publishing it. And in order to do that, you just need to go to extensions, set the developer mode to true, and then load your Unpack extension after you build it. And then if you want, of course, to deploy it, there's a way to do that. You have Chrome Web Store, you have also the Firefox one, and you can just publish it there so everyone can download it, and maybe at some point you can make money out of it. But of course, for this talk, the demo I created, you can use it locally. Just go to the repo, and in this QR code, you have it. So just scan it, go to the repo, download it, try it out, change it, do whatever you want. And thank you so much for listening. I also left in the readme a lot of resources, as you can see here in this slide. And of course, if you have any questions about any developer program like Google Developer Experts, MVP, Women Developers, let me know because I'm part of them, and I would love to help you to join if you want because they give you access to these kind of original trials before anyone else, and that's really cool. So you can find me at Dan Traus in every social media, and let's keep in touch. Thank you so much. Have a nice day.
Comments