Forum Discussion

chetan_sk's avatar
chetan_sk
Copper Contributor
Jul 25, 2023
Solved

Uploading the CSV files to teams channel using python

Hi

I have a requirement of getting data from few sources transforming it using pandas and then generating a CSV or Excel file of to post in microsoft teams programatically.

Is there any way to post the file in teams channel using python via API ? It would be nice to get some insights on this ?

  • chetan_sk - yes, the second option i.e., using bot API, that limits to only personal scope. And as your intent to send files in team's channel you have to go with first approach only.

    The file you intent to send must be already present in SharePoint. Once you fire the API query, it will send message with attachment directly in team's channel. (not as reference link to download the file)



    Thanks, 

    Prasad Das

    ------------------------------------------------------------------------------------------ 

    If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.

5 Replies

  • Ok, that's good:) fwsef??PW???Kx2?z???x5Z?DZ9??3????I????in????2?Y7j?5nd??4b?W?Y??7????9erg

  • chetan_sk -
    Using Graph API:

    Post messages with file attachments that refer to existing SharePoint files, using the Graph APIs for OneDrive and SharePoint. To use the Graph APIs, obtain access to either of the following through the standard OAuth 2.0 authorization flow:

    • A user's OneDrive folder for personal and groupchat files.
    • The files in a team's channel for channel files.

    Graph APIs work in all Teams scopes. 
    Ref: Send chatMessage in a channel or a chat - Microsoft Graph v1.0 | Microsoft Learn

    Using Teams Bot API:

    Teams bot APIs work only in the personal context. They don't work in the channel or groupchat context.

    Using Teams APIs, the bot can directly send and receive files with users in the personal context, also known as personal chats.
    Ref: Send and receive files using bot - Teams | Microsoft Learn
    Sample: Microsoft-Teams-Samples/samples/bot-file-upload/python at main · OfficeDev/Microsoft-Teams-Samples (github.com)



    Thanks, 

    Prasad Das

    ------------------------------------------------------------------------------------------ 

    If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.

     




    • chetan_sk's avatar
      chetan_sk
      Copper Contributor

      Prasad_Das-MSFT Thank-you for your response, 

      To summerise  :

      The second method which you mentioned Using Teams Bot API: works only when we have to send the message to particular user / person in the miscrosoft team and not to the particular channel or group.

       

      That means for our user case, which is posting it to the teams channel or group we need to go ahead with the first approachUsing Graph API: where we send the message in the channel with the reference link to dowload the file from sharepoint and cant share the actual file.

       

      So there is no direct way of posting the file to microsoft teams, it should always be uploaded to sharepoint, Correct if my understanding is wrong.

       

      Also is there any reference for uploading the file to sharepoint via python ?

       

      Regards,

      Chetan

      • Prasad_Das-MSFT's avatar
        Prasad_Das-MSFT
        Icon for Microsoft rankMicrosoft

        chetan_sk - yes, the second option i.e., using bot API, that limits to only personal scope. And as your intent to send files in team's channel you have to go with first approach only.

        The file you intent to send must be already present in SharePoint. Once you fire the API query, it will send message with attachment directly in team's channel. (not as reference link to download the file)



        Thanks, 

        Prasad Das

        ------------------------------------------------------------------------------------------ 

        If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.

Resources