Source code for langchain_community.tools.office365.send_event
"""Util that sends calendar events in Office 365.Free, but setup is required. See link below.https://learn.microsoft.com/en-us/graph/auth/"""fromdatetimeimportdatetimeasdtfromtypingimportList,Optional,TypefromzoneinfoimportZoneInfofromlangchain_core.callbacksimportCallbackManagerForToolRunfrompydanticimportBaseModel,Fieldfromlangchain_community.tools.office365.baseimportO365BaseToolfromlangchain_community.tools.office365.utilsimportUTC_FORMAT
[docs]classSendEventSchema(BaseModel):"""Input for CreateEvent Tool."""body:str=Field(...,description="The message body to include in the event.",)attendees:List[str]=Field(...,description="The list of attendees for the event.",)subject:str=Field(...,description="The subject of the event.",)start_datetime:str=Field(description=" The start datetime for the event in the following format: "' YYYY-MM-DDTHH:MM:SS±hh:mm, where "T" separates the date and time '" components, and the time zone offset is specified as ±hh:mm. "' For example: "2023-06-09T10:30:00+03:00" represents June 9th, '" 2023, at 10:30 AM in a time zone with a positive offset of 3 "" hours from Coordinated Universal Time (UTC).",)end_datetime:str=Field(description=" The end datetime for the event in the following format: "' YYYY-MM-DDTHH:MM:SS±hh:mm, where "T" separates the date and time '" components, and the time zone offset is specified as ±hh:mm. "' For example: "2023-06-09T10:30:00+03:00" represents June 9th, '" 2023, at 10:30 AM in a time zone with a positive offset of 3 "" hours from Coordinated Universal Time (UTC).",)
[docs]classO365SendEvent(O365BaseTool):# type: ignore[override, override]"""Tool for sending calendar events in Office 365."""name:str="send_event"description:str=("Use this tool to create and send an event with the provided event fields.")args_schema:Type[SendEventSchema]=SendEventSchemadef_run(self,body:str,attendees:List[str],subject:str,start_datetime:str,end_datetime:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:# Get calendar objectschedule=self.account.schedule()calendar=schedule.get_default_calendar()event=calendar.new_event()event.body=bodyevent.subject=subjecttry:event.start=dt.fromisoformat(start_datetime).replace(tzinfo=ZoneInfo("UTC"))exceptValueError:# fallback for backwards compatibilityevent.start=dt.strptime(start_datetime,UTC_FORMAT)try:event.end=dt.fromisoformat(end_datetime).replace(tzinfo=ZoneInfo("UTC"))exceptValueError:# fallback for backwards compatibilityevent.end=dt.strptime(end_datetime,UTC_FORMAT)forattendeeinattendees:event.attendees.add(attendee)event.save()output="Event sent: "+str(event)returnoutput