Nouvelles Du Monde

Comment créer un système ac # capable d’envoyer des messages au chat Microsoft Teams ?

Comment créer un système ac # capable d’envoyer des messages au chat Microsoft Teams ?

J’ai créé une application personnalisée en C # pour envoyer un message au chat personnel dans Microsoft Teams. J’ai fait la partie codage, mais lorsque j’exécute l’application, j’obtiens cette sortie. Je ne vois aucun bouton à l’écran et le code ne fonctionne pas, aucune erreur n’apparaît. Est-ce que quelqu’un connaît la solution?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Identity.Client;
using Microsoft.Graph;

namespace Task2
{
public partial class Form1 : Form
{
    static Form1()
    {
    }
  
    private async void BtnSend_Click_1(object sender, EventArgs e)
    {
        var scopes = new[] { "User.Read" };

        // Multi-tenant apps can use "common",
        // single-tenant apps must use the tenant ID from the Azure portal
        var tenantId = "5e5d2xxxxxxx6f8b0";

        // Value from app registration
        var clientId = "0f4c7fxxxxxxxfc1f1d4555";

        var pca = PublicClientApplicationBuilder
            .Create(clientId)
            .WithTenantId(tenantId)
            .Build();

        // DelegateAuthenticationProvider is a simple auth provider implementation
        // that allows you to define an async function to retrieve a token
        // Alternatively, you can create a class that implements IAuthenticationProvider
        // for more complex scenarios
        var authProvider = new DelegateAuthenticationProvider(async (request) =>
        {
            // Use Microsoft.Identity.Client to retrieve token
            var result = await pca.AcquireTokenByIntegratedWindowsAuth(scopes).ExecuteAsync();

            request.Headers.Authorization =
                new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
        });

        var graphClient = new GraphServiceClient(authProvider);

        ChatMessage chatMessage = new ChatMessage();
        chatMessage.Subject = null;
        chatMessage.Body = new ItemBody();
        chatMessage.Body.ContentType = BodyType.Text;
        chatMessage.Body.Content = Contenttxt.Text;

        await graphClient.Chats["19:056680e9-868a-49a2-bf96-2ba2dxxxxxxxxd-843b-3d1104128f25@unq.gbl.spaces"].Messages
 .Request()
 .AddAsync(chatMessage);
        Contenttxt.Text = "";
    }
}

}

Facebook
Twitter
LinkedIn
Pinterest

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

ADVERTISEMENT