Transcript for:
Telegram-Google Calendar Integration

[Music] hello YouTube Friends welcome back to another video in my channel and I hope you're having an amazing day in today's video I'm going to show you how to build an automation using active pieces that connects a telegram bot to Google Calendar for scheduling appointments we'll do it all step by step so you can easily follow along activ is one of my favorite open source automation tools a great alternative to loot tools like zapier or make.com its flow Builder is super intuitive and flexible making it perfect for creating seamless no code workflows so here's the plan for today's automation we're going to set up a telegram bot that allows users to request and schedule appointments and those appointment details will automatically get added into Google Calendar so this is perfect for anyone who wants to streamline their scheduling process whether you're a busy professional or just looking to simplify your day-to-day planning first we'll start by setting up a telegram bot using botf father and I'll show you how to to create one give it a username and grab the API token to integrate with active pieces if you're new to telegram Bots don't worry it's super easy and I'll guide you through step by step and then we'll jump into active pieces so this will include extracting the details like the date time and event and ensuring that events are created correctly using the Google Calendars API and I'll also show you how to customize a telegram notification so that your Bot can confirm appointment request so throughout the video I'll show you how to debug your workflow tweak inputs and refine your automation so it's tailored exactly to your needs if you're new here my name is Dennis and I'm a software engineer and I make videos on coding Ai and automation all right so let's get into it so let's quickly walk through what we're going to be building today so this was inspired by a previous demo that I did uh using edn uh for a scheduling assistant so this was just using the telegram trigger to accomplish and uh create a bot for scheduling appointments inside of Google Calendar right so we used um AI agent to coordinate and be able to create task or get calendar events so we're going to be doing the same thing but it's going to be in active pieces and obviously active pieces do have the AA agent yet so we're going to be using sort of like a manual approach to this automation since they don't have a a agent yet but I'm going to be showing you guys how this works and how you can use Telegram in set of active pieces which is the main point of this video so let's walk you through the diagram real quick so you can see step by step what we're going to be trying to accomplish here so the first thing is we're going to get a telegram message which we're then we're going to be either downloading the message or we're going to be grabbing the text from that message after we get the message we're going to use the LM to determine what type of task the user wants to do or per form so it's either we're going to be doing two things either to create a calendar event or we're going to go through and get the calendar events so those are the two things that we're we're interested in and that we're going to be using as part of this active pieces telegram workflow so we're going to be either retrieving the calendar events or scheduling an event and we're going to be using llm to determine what type of task the user is trying to accomplish after we get all that after we perform the task we're going to send the message back to telegram so essentially that's what we're trying to do here so this is like a big overview of what we're trying to accomplish so we're going to and convert this NN automation into an active pieces and we're going to go through and build all this step by step from scratch all right so let's walk you through how to set up your telegram bot so first we're going to navigate to this URL to be able to interact with the bot father so once you get to this URL you're going to have to start a bot which will open up the telegram desktop if you have it available so we're going to click on open telegram desktop which will open up so from here we can start a conversation with the bot and from the screen you can see here that there's a bunch of commands presented on the screen such as creating a new bot editing the bot and then there some bot settings that you can you know do here so the main thing that we're interested is we want to create a new bot right so once you do a slash new bot you can now name your Bot however you want so we're going to just name this coding menus bot white YT demo we're going to call like that and then and good now let's choose a username for your Bot it must end in a bot so we're going to go and use the same naming scheme so once you're done we're going to be presented with the screen it says congratulations on new bot and then you'll find the bot here so once you click on that link it's going to open up a new conversation with that new bot that you just created and then the main thing here that you want to copy is this token which will allow you to interact with this bot with our API H via HTTP right so we're going to be using this token and to set up our telegram but inside of active pieces so let's quickly jump into active pieces once you get this far into the conversation let's set up this automation from scratch so I have the telegram window here running uh simultaneously on the same window and then I have the activ B on the left hand side let's create a new flow from scratch and then we're going to select the trigger and then we're going to look for a telegram and then we're going to be using uh the new message and we're going to be setting up a new connection and I'm just going to call it the same way that I named my bot here earlier and then I'm going to copy the token all right so far so good so now from here I can load sample data since we haven't entered any data or message on the telegram desktop application we're going to go to that one first so we're going to go to that bot and start interacting with it so the first thing here is we're going to send a text message here and say hello this is a text and then we're going to go back to the pieces and do load sample data so now we got this we got the first result here now we got a data with the text hello this is a text so the next thing that we want to do here is we want to send a voice message right so so we're going to hold this voice icon hello this is a voice uh message or once I send that we're going to do a retest again so the next uh message that we got has a voice property here which includes the M type the duration and also to the file ID which is important later on which is what we're going to be using later on to download the voice message from the telegram API so now I have sample data here so now we have enough data to be able to work with either using text message or voice message so let's work with this the next thing that we need need to do here is we need to send the typing action to the screen so that it can notify the user that something is happening in the background while we're still performing the actions inside of this automation so we're going to look for a telegram step and so since they don't have an action for the typing yet we're going to do a custom API call which where then we're going to be selecting the connection that we just added earlier once you do that it's going to automatically prefill the URL with the token which will be this long string and then we just need to add uh additional uh routing information so that we can interact with their API all right so once we do that we're going to type in in the end after that slash we're going to type in SL send chat action and then this is going to be a get request to the server or actually post request since we're uh sending in adjacent body to this so the next thing here is we're going to put in a body here and for the body we're going to pass in a couple of properties here first the action which is typing and then the chat ID which is what would be coming from the trigger which is the telegram so we're going to test the step and you can see here if you go back to the telegram desktop application you can see that there's a typing happening right up on the top if you miss it I'm go ahead and hit retest again and you can see here that there a visual indicator that something is happening in the background which is what we want so we're going to rename this to send typing action and then let's just rename this as well just rename our flow into telegram demo so the next thing we want to do here is we want to make sure that we know what the message is so whether it's a a voice message or a text so we're going to add a conditional step and we're going to look for conditional so this will allow us to determine whether the voice properly exists so if we go back to the new message here if you go and pull this up you can see that there's a voice property here that's been added so compared to the the text message you can see that it's it's only a text with this text that I sent in comparison you can see that there's a voice property here so that's what we're going to be looking for so this is what the what we're going to be setting into the conditional whether a voice a message was sent versus a text so in the branch we're going to set the new message we're going to set the The Voice property here we're going to just send the whole property and then since we're checking for the existence of a property we're going to and look for exist so we're going to go and check if that property exists as part of the telegram message that was incoming so we're going to go and rename this voice message so if it's a voice message and it it pass our Condition it's going to go and proceeded into this part of the flow otherwise it's going to go ahead and we're just going to assume that it's a text message so once we've determined that it's a voice message we're going to proceed and the next thing that we need to do is to download the message so we're going to look for telegram once again and this uh this time we're going to use custom API call since they don't have an action yet specific to downloading a voice message so we're going to do that so once we have the custom API call we're going to rename this so that download message and then we're going to pick our connection here once I've picked the connection that I want it's going to prefill the URL and this time we're just going to be using a get request here so after the URL we're going to add get file and then question mark file uncore ID and then after that it's going to be equals and then we're going to be setting it to the file ID that we received from the message so we're going to set the the data here from the message and we're going to be looking for the file I did from the voice and then we're going to be setting it to file ID all right so once we do that we can just test this step this intern is going to give us a result of a Json body which is has to okay and then the result and then from here you can see that there's a pile path and also the file unique ID we're mostly interested in the file path to be able to download uh the this OG file that we have here so in order to get the message into open AI we need to be able to download that o file we need to pass in a public L that we can send to openai so before we can do that we need to uh sort of bypass this process by downloading it into Google Drive so we're going to add a Google Drive step so this is like a little trick that I that I found so if you have a better idea of how to accomplish this please leave it down in the comments so I'm going to look for um Google Drive so we're going to do is we're going to be downloading this into uh our own Google Drive and then later on after we send that file into open AI we can just delete that so Google Drive is just an intermediate step so that we can download that into active pieces it's going to create a custom URL that we can pass into open so you can see how a little bit how how it's going to work so we're going to create upload a file here and then for the the file we're going to have to set we're going to select any of our existing connection so doesn't really matter at this case since we're going to be deleting this file later on anyways and then we're just going to be uh do whatever we want want so in this case just to kind of keep it unique just name it the same file that we received which is the file ID which is I'm going to be setting that's going to be the file ID that's going to be sent to Google Drive so as far as the file we're going to set it to URL so I'm going to paste a URL it's going to start with this um same path that we did before except that we're including a SL file before the bot and then after the bot will be the token itself so let's let me grab the token from one of these request so I'm just going to go and grab just entire bot and then I'm going to be passing it as part of this bot request all right so once you got the token the bot and then the token we're going to do a forward slash and then we're going to be passing in the actual file so we're going to go back into the download message you can see here the result includes the the file path which we we can include as part of this process so I have a 10 folder here inside my Google Drive so I'm I just created this right now so go back into active pieces here we're going to set the parent folder let's refresh it so that we we can see the new temp folder that is created so I'm going to pick the temp folder and then we're setting the file path to this uh API URL which includes the token and then we're going to include the going back to the message here and we're going to be setting in the result and then we're going to go and set the file path right so once you get that set uh we're going to do a test step here and this is going to be uploading the O file into a Google Drive you can see here it returned back an ID here and then the M type and then the name and if you go back to Google Drive you see you can see that the file has been uploaded on our Google Drive so going back to active pieces so once you got the up um file we're going to download it again so it's like a temporary thing that we would just have to do so that active pieces can create a URL for us that we can use to pass into openai so we're going to look for Google Drive again and this time we're going to and download the file so we're going to be looking for read file here and then for the read file we're going to use the same connection that I had before and then for the file ID we're going to go back into the uploaded file step and then we're going to be choosing the ID here so once we do that we're going to do a test step here which will allow us to read the file and this is going to read the file to us so now I have a download file now I can send that into openi to to transcribe the audio so the next step here is I want to add an open ey step and then we're going to be using the transcribe audio inside of this we're going to select the connection which I only have one here and then we're going to pass in the audio so the audio would be the reading the file so you can see here if I hover over the read file here you can see that there's an active piece URL that's been created for us we're going to insert it as part of the audio and we're going to do a test step here so this should only take a few seconds one key step that I actually forgot so if you get this type of error that I get here you see that there's invalid type format so if you count something like this you need to make sure that when you download the file it has to be in a certain naming format so we're going to go back to read file and then we're going to you can just type whatever file name here I'm going to call it audio. oga that's going to be the file name when openi receiv receives the URL it's very specific about having this o extension so when you download this file it's going to have this extension now so if you go back to transcribe audio we can do a test step once again so you can see here hello this is a voice message so now we've successfully transcribed the audio from telegram the next step is to do a cleanup by deleting the file that we just uploaded into Google Drive so that we don't create any more clutter so we're going to just add a step here and we're going to be looking for Google Drive and then we're going to go and look for delete and then from here we can just pick the connection that we had before and then the file ID would be going back into setting up the ID and doing a test step here once you do that it should delete the file from our Google Drive directory all right so great so at this point we're able to retrieve the text based on the voice message so if we're going into this path we're going to go and retrieve the voice message text otherwise we're going to retrieve the text message so we have both sides covered at this point so all we have to do now is set the the message inside of a storage so we can retrieve it right at the bottom where the both these conditions meet so like we're going to look for storage and then we're just going to do a put then from here actually I need to put it here inside of this condition and then I'm going to set this one to set so in terms of the key I'm going to just rename mine to message and then the value would be the incoming message from open AI I'm going to go and select the text and then we're going to change the scope into run so that it doesn't really go anywhere else so we're want to keep this variable inside of this run as opposed to exposing it anywhere else in in the project or the flow so we're going to set the message on this side you can see here hello this is a voice message similarly we can also duplicate this and we're going to be sending it to the other side of this condition right so otherwise we're going to get a text so we're going to set the message message here once again but this time this is going to be coming from the text so we're just going to retrieve straight from the telegram text once again so the way we do that is we're going to go back into the message bot and scroll down and then we're going to go and change the result from one to two and now we get this hello this is a text now we can go back here instead of the value of uh openi we're going to go and choose the message and then text and we're can do a test step here once again so make sure that we get the output that we want so now we either get a text message or we can get a voice message so either way either part of the condition we're going to get that message so here at the bottom we're just going to retrieve that the storage key and we're going to use the M same key once again so we're going to set the message here and then get the message and then we're going to do a test step just make sure that we can retrieve that that stored message from either path of the route actually I'm going to hit the run here and then do a retest and you see here hello this is a text since that's what we just said earlier so the next thing that we need to do here so once we get the text is to create a connection to the llm to be able to par out the message and make sure that we understand what what the user is requesting for whether we want to create an event or we want to just get the list of events so we're going to create a request to nlm so we're going to be using straco here and we're just going to be using ask Ai and I'm just going to be copying a prompt here so I'm going to select my connection and then for this one I'm just going to be using the open Ai and I'm going to be using the 03 mini high and then for the prompt I'm paste it here so act as a data processor to generate a Json output with the following properties start date and and date event name event description and task analyze the message content to categorize the task as either schedule or retrieve schedule and assign this ceger to the task property extract the T start and end dates from the message if um if there's no specific dates are mentioned default to to today's start and end date and time and the date will be in ISO format and it will include the time zone of PST for the start and end Aid since I've set my my Google Calendar to a specific time zone I want to make sure that when the llm PRS out the date for the start and end time it should be in the correct format already for my specific time zone and then assume this year is the current date so we're going to grab the current date so have a little bit of context uh where we at at the current time since the model's training date could be from the previous year so we're going to set that and then return the result in Json without additional markdown code since it tends to use some markdown code sometimes and for the message we're just going to pass in the storage so we're going to go back into the storage here and get the message it's going to be the message and then as far as the date we're going to add a preceding step which we're going to look for the date I believe it's get current date get current date and then we're just going to pick a time zone here which I am in Los Angeles and then I'm going to be using the best format that I think would be good for this which which is in my case would be the month day and year type of format and let's just do a test here making sure and then now we can pass that date inside of that s aai so I'm going to back out here and remove this and then I'm just going to insert the date that we just retrieved which is this one I don't have a good message here but let's do a test step later on we're just going to do a proper text message so we can do a full test of this but just for now just to make sure that we're getting the the proper format that we want let's just do a test step so after a few seconds you can see that there's a start end date in the correct time zone and then the event name is hello event description this is a test and then to re schedule which is not since we didn't tell it what to do when it doesn't really fall into one of those two type of conditions we're going to get this type of result so this is something that we can work with for now so once we get the response from the M let's click on it as you can see here we get the start date the end date the event name and the event description and the task now we're going to convert that string into Json so we can use it in our flow so we're going to add a step here and look for Json and we're going to look for convert text to Json and then we're going to be passing in the text here which we're just going to insert the output from straco and then we're going to do a test step so this is going to give us the usable uh Json that we can use in our flow which gives us start date end Date event name event name event description and the task itself so now we want to do something based on the task that user has requested so remember that we looking for either retrieve schedule or schedule which will allow us to determine which task to perform so we're going to have to add a condition here or a route so we're going to look for a router here and then we're going to be checking the task from the previous step So based on this rou we're going to on on our first Branch we're going to and pass in the task itself and we want to make sure that the text exactly matches retrieve schedule all right we to go ahead and do a test step here and as you can see the branch one it's true and then otherwise it's going to be false and let's rename this just to make sure that we know what each individual path does so we're going to rename this through retrieve schedule and then for we're going to do a secondary brand here and we're going to be looking for the schedule so we're going to do a we're going to pass in the same task and then we're going to change this to exactly match and then we're going to be checking for schedule here so we're going to rename the branch as well to schedule and then let's do a test step here as well just to verify so same result as before as you can see here the Reet schedule is true evaluation and then the branch name for schedule is false and then otherwise it's going to be fals so if we fall outside of those two criterias or tasks uh we're just going to respond to the user that we can't determine what the task is about right and for that let's take care of the otherwise first we're going to go and look for telegram and we're going to go and do a send text message we're going to be choosing the bot token that we set up earlier and we're going to be passing in the chat ID which is coming from the trigger we're going to go and go to trigger chat ID and then we're going to by passing that in and then we're going to keep the formats marked down like previously and then for the message we're just going to keep it simple it's just going to be a static data I cannot figure out what the message is about and then make sure that we escape the period by doing a backslash here would you like to get a list of events or schedule a calendar event so we're going to do a test St here and you can see that it's able to send that into the telegram all right so let's take care of The Next Step which is to retrieve the SCH so if we fall on the retrieve schedule uh side of the condition we're going to retrieve the schedule for the calendar so we're going to go and add a step here and we're going to search for Google Calendar and then we're going to go and do a get all events so from here we're going to go and and choose our connection and we're going to be uh choosing the calendar that we want to retrieve a the events for we're just going to keep the event types as is the default Focus time and out of office uh we're going to leave this search term as is and then from we're going to be grabbing the from from the start date so we're going to be passing it a start and end date range and then for the end date we're going to go and set it to end date here so I think that's going to be it we're going to do a retrieve step and if you scroll down to the bottom so you can see here that there's a this a test description hello this is what we added earlier so we were able to retrieve the events so once we have retrieved the events we're going to clean up all the different events in there so if you look at the body that came back from doing a get all events you can see here that you see an item here but we're going to see that we're going to get all these different properties as well so e tag the kind and ID which we don't want we want to clean this up a little bit so we're going to do a code here and then we're going to be look looking for code piece and then we're going to look for custom JavaScript code right so we're going to go and rename this to clean up uh events and then for the inputs we're going to just pass in events here and then we're going to be passing in the events from the calendar that we just did earlier so we're just going to go and pass in the items and then I'm just going to paste the code and I'm going to explain it to you guys so once we get the events passed in here it's going to come in as an input so all we have to do is just going to go and retrieve that event by just doing a map to it right so we're just going to go through each event and then we're just going to determine which properties in that event are we going to sent back so we're going to declare a date here there's going to be some events where it's going to include the start and end time so we want to make sure that we anticipate that that those properties exist so if the start and end time exist we're just going to assign it to this date otherwise it's just going to we're just going to pass in the the date as just a regular date here so we don't have the start and end time uh part of the date so we're going to go ahe and return the URL for that event uh which is in this HTML link and then the summary of the event as well as the date itself so if you do a test step here we should get back an array of of events which is a clean up version of what we have before which includes the URL the summary and the date in this case since we have a date range it's going to include the start date of this and then it's going to have an end dat of that right so once we have that ready to go we're going to pass it to llm so that we can send it back as a message to Telegram in a cleaner format that it's easier to read so we're get we're add a second Next Step here and then we're going to be using stco for this and we're going to be using ask AI so the for for the connection I'm going to set the connection here and for the model I'm going to use cloud 3.7 Sonet and then for the prompt I'm just going to paste a prompt here act as a marked down formatter given the Json uh array below give converted to to marked unformatted response that is easy to read ensure that the URL is clickable for easy navigation to the event do not include additional commentary in the out in the output provide the markdown for uh output in the exact format as the example below the date has to be in these this format right here which is the mmdd Y format and then include the time so I've given it some instructions here and what the output should look like so it's going to include this format right here which if it includes time it's going to go and going to give you as time and then the link to the event otherwise it's going to give you a just a regular date here with no start or end time whatsoever so that's going to be the format that we want and then we're going to be passing in the events here so we're going to be passing in the events which is coming from the previous step right here so you can see that there's an array and then we're just going to insert that so let's do a test step here since we have a single event that we just passed in as part of the uh the input for the The Prompt we we're going to get this uh output right here which has too and then the date and then the view the event here which includes an an event URL that the user can easily click on and it will take them straight to that event so the last thing that we need to do here is we need to send back to telegram for this path and we're going to send text message and then we're going to be uh sending it to that that token that we just set earlier we're going to set it to the chat ID and then we're just going to keep the mark mark down format and then for the message we're just going to pass in the result from the previous step so if I do a test step here we should be able to get this message which is hello 226 220 2025 and a a link to the event in Google Calendar so the next thing that we need to tackle here is the scheduled type part of the condition which we're allowing them to schedule an appointment so we're going to be doing the same thing as previously we're going to have to retrieve all the schedules once again to avoid any conflict in scheduling so we don't schedule the same uh type of vent on the same uh date in time slot so we're just going to duplicate this and we're going to drag it to the schedule and I'm going to go and rename this so we're going to do a test step here once again so once we got our output we're going to be doing a check so let's collapse this and I'm going to click on it and I'm going to go a conditional here so we're going to do the same thing where we're going to be checking if there's any events so we're going to do a router here and then we're going to be checking if there's any events so we're going to be doing the opposite of what we did on the previous condition so for this condition we're just going to check uh we're going to go to the get all events and we're going to be passing in the the body and the items and I'm just going to start it here so we want to do opposite so we're looking for the list being empty so no events so if there's no events we're just going to go and schedule that event otherwise we're just going to go and send back a message that says that we can't schedule that due to a conflict so let's take care of the otherwise first since that's the easiest so let's look for telegram once again send a text message and then pick our connection and then uh we're going to pick the chat ID and then we're going to escape the format of markdown and then for the message we're just going to say I'm enabled to book that a event do a 2 TOA conflict in schedule and then we're going to escape the period at the end we're going to do a test step here and that will send the message to the user so let's take care of the no events which will allow us to create the event so let's go ahead and add a step here and look for Google Calendar and we're going to create an event right so we're going to pick the connection and we're going to be choosing the calendar the title of the event is going to be coming from convert text to Jason which we did earlier here we just going to pass in the event name and the start name start date time of the event which is going to be passing the start date time and then for the event or end date we're just going to pass in the end date and for the description let's pass in the description as well and then that should be good to go jumping back into my Google Calendar here you can see that I have a 1200 a.m. hello here already I'm just going to delete that so we can execute the step once again I'm going to do a test step here just to make sure that it's working as expected and that should you see that tested successfully and then it was able to get back the ID so if you go back into Google Calendar I'm go to refresh this and you can see here that the calendar event has been added for the state so once we have created uh the event successfully in Google Calendar let's respond to the user stating that the calendar event has been successfully been added so before we do that let's actually convert the start end time into a a string that's can be used in that message so let's do search for a date here we're going to be looking for date Helper and then we're going to be doing a format date and we're going to be looking to convert this start date in this format as you can see here it looks like with the year first and then the the month and the day and then includes the time zone and then we're going to convert that so let's pick a format here that closely resembles that format so we're going to choose that and then we're going to convert it to this time zone so I'm going to be choosing my time zone here and then I'm going to be converting it into a format that uh I prefer which is the the m and then y y and then I'm going to convert it to the time zone here and do a test step for this so now we get the the output that we want for the date we can send back a message to the user let's do a a telegram once again let's do add a step here send text message same as before same connection and then we're going to tie it back into the original chat ID and then the formats marked down and then we're just going to paste the message here for the event uh we're going to go and retrieve it from the Json so we're going to go and go back and look for that Json event name and then we're going to pick the event the format format date for that start date so which is this one right here so once we do that let's do a test step here which should send back this if hello on 226 to 20 uh 2025 has been created so now that we've successfully taken care of the two different places right so one for the retrieving schedule which will allow us to retrieve the schedule and then the next part of the condition is we're able to get the schedule or actually create a schedule for that but before we able to create a schedule for that event we're able to get all the different events and make sure that there's no schedule conflict so before we wrap this up I just want to make sure that all the different path here whether we're going through through schedule or we're doing a to just create a schedule we're making sure that we're returning back a message regardless of which path we take right so if we're not able to retrieve the intent or the task we're going to just send back something in terms of letting them know that we're not able to retrieve the task so as far as retrieving schedule we were able to retrieve the schedule and send back a message to the user that we're able to get all the different events for that date otherwise we're just going to do a schedule here which will allow us to get all the events here before even attempting to create a schedule for that event and then if there's a conflict uh we're able to send a message that uh there's a conflict in schedule otherwise it's going to send back that the event has been created successfully so there you have it an efficient easy to use automation that links your telegram bot directly to Google Calendar using active pieces I hope that this video has been helpful and has inspired you to dive into the world of Automation and as always uh feel free to leave your questions down in the comments I love hearing from you guys and I'm always happy to help uh where I can so thank you so much for watching and I'll see you guys on the next video