-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathJoinInfo.cs
More file actions
112 lines (100 loc) · 4.82 KB
/
Copy pathJoinInfo.cs
File metadata and controls
112 lines (100 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// <copyright file="JoinInfo.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>
namespace Sample.Common.Meetings
{
using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Graph;
/// <summary>
/// Gets the join information.
/// </summary>
public class JoinInfo
{
/// <summary>
/// Parse Join URL into its components.
/// NOTE: This method only works with the OLD Teams meeting URL format that includes a context parameter.
/// For NEW shorter Teams meeting URLs (introduced with MCnumber rollout), you should:
/// 1. Use the Graph API to query the OnlineMeeting by JoinWebUrl to get meeting details.
/// 2. Use JoinMeetingIdMeetingInfo with the meeting ID and passcode from the API response.
/// Example: var meeting = await graphClient.Communications.OnlineMeetings.Request().Filter($"JoinWebUrl eq '{encodedUrl}'").GetAsync().
/// </summary>
/// <param name="joinURL">Join URL from Team's meeting body.</param>
/// <returns>Parsed data.</returns>
public static (ChatInfo, MeetingInfo) ParseJoinURL(string joinURL)
{
if (string.IsNullOrWhiteSpace(joinURL))
{
throw new ArgumentException($"Join URL cannot be null, empty, or whitespace: {joinURL}", nameof(joinURL));
}
var decodedURL = WebUtility.UrlDecode(joinURL);
//// Old URL format with context parameter:
//// https://teams.microsoft.com/l/meetup-join/19:cd9ce3da56624fe69c9d7cd026f9126d@thread.skype/1509579179399?context={"Tid":"72f988bf-86f1-41af-91ab-2d7cd011db47","Oid":"550fae72-d251-43ec-868c-373732c2704f","MessageId":"1536978844957"}
//// New shorter URL format (not supported by this parser):
//// https://teams.microsoft.com/l/meetup-join/...
var regex = new Regex("https://teams\\.microsoft\\.com.*/(?<thread>[^/]+)/(?<message>[^/]+)\\?context=(?<context>{.*})");
var match = regex.Match(decodedURL);
if (!match.Success)
{
// Check if this is a new shorter URL format
if (decodedURL.Contains("teams.microsoft.com") && decodedURL.Contains("/meetup-join/") && !decodedURL.Contains("?context="))
{
throw new NotSupportedException(
$"This appears to be a new shorter Teams meeting URL format which is not supported by this parser. " +
$"To join meetings with this URL format, please use the Graph API to resolve the meeting details:\n" +
$"1. Query: GET /communications/onlineMeetings?$filter=JoinWebUrl eq '{Uri.EscapeDataString(joinURL)}'\n" +
$"2. Use JoinMeetingIdMeetingInfo with the meeting.JoinMeetingIdSettings from the response.\n" +
$"See: https://learn.microsoft.com/graph/api/resources/joinmeetingidmeetinginfo");
}
throw new ArgumentException($"Join URL cannot be parsed: {joinURL}.", nameof(joinURL));
}
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(match.Groups["context"].Value)))
{
var ctxt = (Context)new DataContractJsonSerializer(typeof(Context)).ReadObject(stream);
var chatInfo = new ChatInfo
{
ThreadId = match.Groups["thread"].Value,
MessageId = match.Groups["message"].Value,
ReplyChainMessageId = ctxt.MessageId,
};
var meetingInfo = new OrganizerMeetingInfo
{
Organizer = new IdentitySet
{
User = new Identity { Id = ctxt.Oid },
},
};
meetingInfo.Organizer.User.SetTenantId(ctxt.Tid);
return (chatInfo, meetingInfo);
}
}
/// <summary>
/// Join URL context.
/// </summary>
[DataContract]
private class Context
{
/// <summary>
/// Gets or sets the Tenant Id.
/// </summary>
[DataMember]
public string Tid { get; set; }
/// <summary>
/// Gets or sets the AAD object id of the user.
/// </summary>
[DataMember]
public string Oid { get; set; }
/// <summary>
/// Gets or sets the chat message id.
/// </summary>
[DataMember]
public string MessageId { get; set; }
}
}
}