Example #1
0
        public static TeamsTabInfo GetTabInfoFromAppManifest()
        {
            if (tabInfo == null)
            {
                string           tabManifestContent = File.ReadAllText("manifest.json");
                TeamsAppManifest manifest           = JsonConvert.DeserializeObject <TeamsAppManifest>(tabManifestContent);
                tabInfo               = new TeamsTabInfo();
                tabInfo.DisplayName   = manifest.DisplayName;
                tabInfo.Configuration = manifest.ConfigList[0];
            }

            return(tabInfo);
        }
        //https://docs.microsoft.com/en-us/graph/api/teamstab-add?view=graph-rest-1.0
        public static async Task AddCustomTabAsync(string groupId, string channelId, TeamsTabInfo tabInfo, HttpClient graphHttpClient)
        {
            //Read the graph document to update the api path
            var apiPath = "Please update the api path";

            HttpContent         content  = new StringContent(JsonConvert.SerializeObject(tabInfo), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await graphHttpClient.PostAsync(apiPath, content);

            string responseMsg = await response.Content.ReadAsStringAsync();

            if (response.StatusCode != HttpStatusCode.Created)
            {
                throw new FocusException($"Create teams channel tab graph call failed: {responseMsg}");
            }
        }
Example #3
0
        static async Task MainAsync(string[] args)
        {
            using (GraphClientManager manager = new GraphClientManager())
            {
                string groupId = await GroupHelper.GetDemoGroupId(manager.GetGraphHttpClient());

                string channelName = "TestChannel -" + DateTime.Now.ToString("yyyyMMddmmss");
                string channelId   = await TeamsHelper.CreateChannelAsync(groupId, channelName, manager.GetGraphHttpClient());

                TeamsTabInfo           tabInfo       = Utility.GetTabInfoFromAppManifest();
                IEnumerable <TeamsApp> installedApps = await TeamsHelper.GetInstalledAppsAsync(groupId, manager.GetGraphHttpClient());

                TeamsApp targetApp = installedApps.FirstOrDefault(m => string.Equals(m?.Definition?.DisplayName, tabInfo.DisplayName, StringComparison.OrdinalIgnoreCase));
                if (targetApp != null)
                {
                    tabInfo.Id = targetApp.Definition.TeamsAppId;
                    await TeamsHelper.AddCustomTabAsync(groupId, channelId, tabInfo, manager.GetGraphHttpClient());
                }
                else
                {
                    throw new FocusException($"app {tabInfo.DisplayName} not installed");
                }
            }
        }