-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathJoinInfo.cs
More file actions
104 lines (92 loc) · 3.78 KB
/
Copy pathJoinInfo.cs
File metadata and controls
104 lines (92 loc) · 3.78 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
// <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.
/// </summary>
/// <param name="joinURL">Join URL from Team's meeting body.</param>
/// <returns>Parsed data.</returns>
public static (ChatInfo, MeetingInfo) ParseJoinURL(string joinURL)
{
var decodedURL = WebUtility.UrlDecode(joinURL);
//// Long URL format:
//// 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"}
var regex = new Regex("https://teams\\.microsoft\\.com.*/(?<thread>[^/]+)/(?<message>[^/]+)\\?context=(?<context>{.*})");
var match = regex.Match(decodedURL);
if (match.Success)
{
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);
}
}
//// Short URL format:
//// https://teams.microsoft.com/meet/2414128301281?p=NzhDLMLT8b07DrkwkE
var shortUrlRegex = new Regex("https://teams\\.microsoft\\.com/meet/(?<meetingId>[^?]+)\\?p=(?<passcode>.+)");
var shortUrlMatch = shortUrlRegex.Match(decodedURL);
if (shortUrlMatch.Success)
{
var meetingInfo = new JoinMeetingIdMeetingInfo
{
JoinMeetingId = shortUrlMatch.Groups["meetingId"].Value,
Passcode = shortUrlMatch.Groups["passcode"].Value,
};
return (new ChatInfo(), meetingInfo);
}
throw new ArgumentException($"Join URL cannot be parsed: {joinURL}.", nameof(joinURL));
}
/// <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; }
}
}
}