Skip to content

Commit

Permalink
[Bug] - FAQPlus configuration app does not allow thread.tacv2 team id…
Browse files Browse the repository at this point in the history
… support (#93)

[Fix] - use regex expression to  identify team id structure instead of hard coded dependency on thread.skype.

_note_: the fix will work with team id with thread.skype as well.
  • Loading branch information
abbodh authored Mar 4, 2020
1 parent 08a6978 commit bf6028d
Showing 1 changed file with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration.Controllers
{
using System;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
Expand All @@ -19,11 +19,6 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration.Controllers
[Authorize]
public class HomeController : Controller
{
private const string TeamIdEscapedStartString = "19%3a";
private const string TeamIdEscapedEndString = "%40thread.skype";
private const string TeamIdUnescapedStartString = "19:";
private const string TeamIdUnescapedEndString = "@thread.skype";

private readonly ConfigurationProvider configurationPovider;
private readonly IQnAMakerClient qnaMakerClient;

Expand Down Expand Up @@ -225,24 +220,17 @@ public async Task<string> GetSavedHelpTabTextAsync()
/// <returns>team Id as string</returns>
private string ParseTeamIdFromDeepLink(string teamIdDeepLink)
{
int startEscapedIndex = teamIdDeepLink.IndexOf(TeamIdEscapedStartString, StringComparison.OrdinalIgnoreCase);
int endEscapedIndex = teamIdDeepLink.IndexOf(TeamIdEscapedEndString, StringComparison.OrdinalIgnoreCase);

int startUnescapedIndex = teamIdDeepLink.IndexOf(TeamIdUnescapedStartString, StringComparison.OrdinalIgnoreCase);
int endUnescapedIndex = teamIdDeepLink.IndexOf(TeamIdUnescapedEndString, StringComparison.OrdinalIgnoreCase);

string teamID = string.Empty;
// team id regex match
// for a pattern like https://teams.microsoft.com/l/team/19%3a64c719819fb1412db8a28fd4a30b581a%40thread.tacv2/conversations?groupId=53b4782c-7c98-4449-993a-441870d10af9&tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47
// regex checks for 19%3a64c719819fb1412db8a28fd4a30b581a%40thread.tacv2
var match = Regex.Match(teamIdDeepLink, @"teams.microsoft.com/l/team/(\S+)/");

if (startEscapedIndex > -1 && endEscapedIndex > -1)
{
teamID = HttpUtility.UrlDecode(teamIdDeepLink.Substring(startEscapedIndex, endEscapedIndex - startEscapedIndex + TeamIdEscapedEndString.Length));
}
else if (startUnescapedIndex > -1 && endUnescapedIndex > -1)
if (!match.Success)
{
teamID = teamIdDeepLink.Substring(startUnescapedIndex, endUnescapedIndex - startUnescapedIndex + TeamIdUnescapedEndString.Length);
return string.Empty;
}

return teamID;
return HttpUtility.UrlDecode(match.Groups[1].Value);
}

/// <summary>
Expand Down

0 comments on commit bf6028d

Please sign in to comment.