rcarette
rcarette

Reputation: 111

Google Calendar Api : How to send notification email to attendee when i add it to an event?

I am updating availables shifts in a google calendar to book meetings. I would like to send a email invitiation when I add a new attendee.

I have tried event.sendNotifications but it is now deprecated.

So I move on event.sendUpdates = 'all' but it is raising an error :

NoMethodError in PagesController#book undefined method sendUpdates=' for #<Google::Apis::CalendarV3::Event:0x00007ff2a9b12ff8>

Here is my code :

service = init_google_api
event_id = params[:id]
event = service.get_event(ENV['CALENDAR_ID'], event_id)
event.summary = "confirmed"
event.sendUpdates = 'all'
event.attendees = [
  {
    email:'[email protected]',
    responseStatus: 'accepted'
  }
]
result = service.update_event(ENV['CALENDAR_ID'], event.id, event)

event = service.get_event(ENV['CALENDAR_ID'], event_id)
result = service.update_event(ENV['CALENDAR_ID'], event.id, event)

When I remove the line event.sendUpdates = 'all', everything is working well.

If someone knows how to fix it or where is my error. Thanks !

Upvotes: 0

Views: 530

Answers (1)

Tanaike
Tanaike

Reputation: 201368

At calendar API, sendUpdates is used as the query parameter. So how about this modification?

From:

result = service.update_event(ENV['CALENDAR_ID'], event.id, event)

To:

result = service.update_event(ENV['CALENDAR_ID'], event.id, event, send_updates: 'all')

Reference:

If this was not the result you want, I apologize.

Upvotes: 4

Related Questions