-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathJoinInfo.cs
More file actions
117 lines (102 loc) · 4.19 KB
/
Copy pathJoinInfo.cs
File metadata and controls
117 lines (102 loc) · 4.19 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
113
114
115
116
117
// <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.Collections.Generic;
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);
//// Shorter URL format: https://teams.microsoft.com/meet/<meetingId>?p=<passcode>
var shortUrlRegex = new Regex("https://teams\\.microsoft\\.com/meet/(?<meetingId>[^?]+)(?:\\?p=(?<passcode>[^&]+))?");
var shortUrlMatch = shortUrlRegex.Match(decodedURL);
if (shortUrlMatch.Success)
{
var meetingId = shortUrlMatch.Groups["meetingId"].Value;
var passcode = shortUrlMatch.Groups["passcode"].Success ? shortUrlMatch.Groups["passcode"].Value : null;
var additionalData = new Dictionary<string, object>
{
{ "joinMeetingId", meetingId },
};
if (passcode != null)
{
additionalData["passcode"] = passcode;
}
var meetingInfo = new TokenMeetingInfo
{
ODataType = "#microsoft.graph.joinMeetingIdMeetingInfo",
AdditionalData = additionalData,
};
return (null, meetingInfo);
}
//// URL being needs to be in this 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)
{
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; }
}
}
}