Microsoft Teams Connector for meetup.com: Part 2

In my previous post I explored how to get event data from meetup.com using PowerShell. View Microsoft Teams Connector for meetup.com: Part 1 for example code and API calls.

In this post I’ll add an Incomming Webhook connector to Microsoft Teams and post meetup events into team channels so that everyone can see upcoming events and get a reminder on the day.

I started by creating a team called ‘MS Team Experiments’ with two channels named ‘Test Channel 1’ and ‘Test Channel 2’. Despite the names the connector is fully functional and working, the experiment team just allowed me to test out different string formats until I got the effect I wanted.

MSTeamChannels.PNG

Right clicking on Test Channel 1 ellipsis ‘…’ exposes the Connectors context menu.

MSTeamChannelConnector.PNG

Add an ‘Incoming Webhook’ connector named ‘Meetup Events’ and upload the meetup icon.

ConnectorConfig.PNG

When you create or manage the configured connector, the URL for the webhook will be displayed. Copy it somewhere safe, you’ll need it in the next step. https://outlook.office.com/webhook/{SecureString}/IncomingWebhook/{SecureString}

The webhook is channel specific so I created multiple webhooks, one for each channel I wanted to connect.

Using PowerShell to post messages to Microsoft Teams

Now for the fun part. Let’s post a simple message to the channel.


$webhook = 'https://outlook.office.com/webhook/{secureString}/IncomingWebhook/{secureString}'
$body = @{
Text = "Hello from PowerShell!"
}
Invoke-RestMethod -Method Post -Uri ($Webhook) -Body (ConvertTo-Json $body -Depth 4)

ChannelTest.PNG

Wow! That was easier than I thought.

Let’s stick the meetup.com event data from part 1 into a hashtable and post it to the channel.


# Generate the same map link that meetup.com display on their pages
$map ="https://maps.google.com/maps?f=q&hl=en&q=" + [System.Web.HttpUtility]::UrlEncode($event.venue.name + ',' + $event.venue.address_1 + ',' + $event.venue.city + ',' + $event.venue.country)
$venue = ($event.venue.name + ', ' + $event.venue.city + ' ([View Map](' + $map + '))' )

$body = @{ Title = ('Reminder: ' + $event.name + ' at ' + $eventTime.ToString("h:mm tt") )
Summary = "Reminder for upcoming event"
themeColor = "E81123"
Sections = @(
@{
ActivityTitle = '[' + $event.group.name + '](' + $event.link + ')'
ActivitySubtitle = '**' + ($eventTime.ToString("dddd d MMMM h:mm tt") + '** (' + $event.yes_rsvp_count + ' are going)' )
ActivityText = $venue
ActivityImage = ($event.group.photo.thumb_link)
Text = '## Like this message if you are going! @mention others that may be interested!'
}
@{ Text = ($event.description)
}
)
}

ReminderToday

Awesome! Expanding the ‘See More’ link will show the full event description.

I’m using the Office 365 card formatting options ActivityTitle, ActivitySubtitle, ActivityText and ActivityImage to display the meetup group image alongside the event details, and the ThemeColor to draw a red border at the top of the message.

You can read about the different Office 365 card formatting options on the Connectors API Reference page.

To create a summary list of the next 12 upcoming meetup events taking place in the next 30 days we can iterate through a list of event data to create a hashtable array of essential ‘facts’.


$upcomingEvents = $events | Sort-Object time | Select-Object -First 12 # Maximum number of events to show in summary
$fact = @()
ForEach ($event In $upcomingEvents) {
$eventTime = (Get-Date 1/1/1970).AddSeconds($event.time/1000).ToLocalTime()
If ($eventTime -ge (Get-Date) -and $eventTime -le (Get-Date).AddDays(30)) {
$fact += @{name = ($eventTime.ToString("ddd dd MMM HH:mm").ToUpper()); value = ($event.group.name + ': [' + $event.name + '](' + $event.link + ')' )}
}
}
$body = @{
Text = "Check out these upcoming events!"
Sections = @(
@{
Facts = @($fact)
}
)
}

SummaryList

The Office 365 connector cards do not currently support data tables and there isn’t markdown support for tables so I’m using the ‘facts’ card element to render a list of key value pairs. It’s good enough for now.

I found some of the meetup groups that had long group names or long event names that made the summary wrap on to multiple lines. If the fact was over 90 chars I chose to remove the common words ‘meetup’ ‘user’ and ‘group’ from the group name and if it was still over 90 chars then truncate it and show elipisis ‘…’.

Some of the meetup groups set their group status to ‘limited public’ so the time and title of events is public but the venue and / or description are only visible to group members. I added &fields=group_photo,venue_visibility,visibility to the api.meetup.com request and changed the detail card content depending upon if ($event.venue_visibility -eq ‘public’) as shown in this example:

VenueNotVisible.PNG

The complete PowerShell scripts can be downloaded on my GitHub page. They will post Melbourne events to channel 1 and Sydney events to channel 2.

The next phase of this project would be to turn these scripts into a full app or bot that can store configurations, cache data, and interact with the conversations!

Overall I’ve been really impressed by Microsoft Teams, and by how easy it was to create this connector. I love experimenting with new technology and I love the local tech community. There are so many events the hardest part is deciding which meetups to attend!

In my final post in this series I’ll add a scheduled task to send posts to the channels using  Azure functions.

See Microsoft Teams Connector for meetup.com: Part 3

Advertisements

One thought on “Microsoft Teams Connector for meetup.com: Part 2

Comments are closed.