Giter Site home page Giter Site logo

pymsteams's People

Contributors

alexadams-ms avatar andrewrezy avatar aviadlevy avatar calvma avatar dependabot[bot] avatar dritzii avatar gmar1274 avatar gmi-joelbondurant avatar matmunn avatar michael131468 avatar nickolay-github avatar nsano-rururu avatar pammys avatar rh-sdavey avatar rveachkc avatar sagland avatar seonin avatar stmoody avatar szemek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymsteams's Issues

Can't POST to webhook if too many characters

Describe the bug
Can't send webhook if it's too many characters in it.

To Reproduce
Steps to reproduce the behavior:
Try to send ALOT of characters

Expected behavior
Expected to send information to my chanell using webhook. But it just do nothing. All works when using command myTeamsMessage.printme()
Everything works then sending couple of lines.

'Promisify' the message shipment

I am using MS Teams as my repository for some logging.

As you know, sending a message in a channel is quite slow and I don't really care about seeing it live as long as the info makes its way to the channel eventually.

So a perfect solution would be to promisify the actual message sending so I could basically continue my script while the message is being sent and decide (or not in that case) to do something about it once it is sent without waiting for the message to be sent before continuing.

Maybe this is already possible with existing tools in which case I'm very happy to get some pointers and work on it.

Posting variable contents

Does pymsteams support user defined variables in messages instead of straight text?
For example I want to post the contents of the following but can't since they are enclosed in quotes. Tried escaping them with no luck. Is this possible?

myTeamsMessage.title("sys.argv[1] sourceDescription interfaceID statusString")

Bug: Search doesn't work with messages sent through pymsteams

I'm using pymsteams to send alerts about my system to a channel. Each message contains a unique ID in the message body, which can be used to reference a specific message. The code I use looks like this:

teams_obj = pymsteams.connectorcard(HOOK_URL)
title = 'title'
activity_title = 'activity_title'
activity_subtitle = 'activity_subtitle'
body = 'body'

section = pymsteams.cardsection()
section.title(title)
section.activityTitle(activity_title)
section.activitySubtitle(activity_subtitle)
section.text(body)
teams_obj.addSection(section)
teams_obj.send()

However, I see that the search functionality in Teams does not consider messages posted through pymsteams (like it's not been indexed?). Is this expected behaviour from the Teams API or is this something specific to pymsteams?

Feature Request: File upload/attachment support

Please add support to use Teams' Attach File feature. This would be extremely helpful for my use case, the lack of it in pymsteams is causing me to look at switching to another solution. Thank you for pymsteams, however, it is very clean.

'body' for addAction

From the documentation I can see that we have the option to add action buttons which when clicked can then perform an HttpPOST. My questions are:

  1. where can you specify the value of the 'data' payload in the HTTP POST , or as MS Teams documentations lists it as , the 'body' value?
  2. how can I take the value of what is entered in the TextInput and place it into the body of the HTTP POST action.
  3. I have been working on composing a webhooks message with action buttons and HTTP POST actions (this is just using curl and not this python module). Teams receives and displays the message but the HTTP POST behind the action button never works. I've tested it extensively. Could it be that this option no longer works as there is mention that using the Connector Messages with Teams is depreciated? Has anyone encountered this problem?

Potentialaction w/out input/actions ?

Hello,
I can't find a way to add a potentialaction without actions: [] array. I'd need to add something like this:

    {
      "@type": "HttpPOST",
      "name": "Click Me",
      "target": "https://...",
      "body": "{'a': 'b'}"
    }

(https://messagecardplayground.azurewebsites.net/ and "Github issue opened sample"). This adds a button you can just click and teams does POST straight away (without displaying any additional buttons/inputs).

I made a patch that adds addRawPotentialAction function for this (https://github.com/jjh74/pymsteams/tree/raw_potentialaction2) if this looks reasonable/acceptable I can create a PR for this.

How to attach a file that can be downloaded?

Can I attach a csv file to Teams message? If not, is it possible to generate a link using python script for box and pass it in download button from where it can be downloaded?

Attach Multichoices values to HttpPost header or body

Now I have a dropdown of multichoices for the users to click on, and a 'send' button to make an Http call to my backend function. The idea is that whenever somebody make a choice from the fropdown, and make an HTTP post call to my backend function, the function will send a follow up message containing the information related to the user choice.

I was wondering if there is any way we could attach the choice values to the HTTP post call header or body?

OpenUri does not show up

I was trying to add a potential action to open an URL. However, after running the following code snippet:

    team_message = pymsteams.connectorcard(URL)
    myTeamsPotentialAction1 = pymsteams.potentialaction(_name="Add a comment")
    myTeamsPotentialAction1.addInput("TextInput", "comment", "Add a comment here", False)
    myTeamsPotentialAction1.addAction("HttpPost", "Add Comment", "https://...")

    myTeamsPotentialAction2 = pymsteams.potentialaction(_name="Set due date")
    myTeamsPotentialAction2.addInput("DateInput", "dueDate", "Enter due date")
    myTeamsPotentialAction2.addAction("HttpPost", "save", "https://...")

    myTeamsPotentialAction3 = pymsteams.potentialaction(_name="Change Status")
    myTeamsPotentialAction3.choices.addChoices("In progress", "0")
    myTeamsPotentialAction3.choices.addChoices("Active", "1")
    myTeamsPotentialAction3.addInput("MultichoiceInput", "list", "Select a status", False)
    myTeamsPotentialAction3.addAction("openUri", "Confirm", "https://...")

    team_message.addPotentialAction(myTeamsPotentialAction1)
    team_message.addPotentialAction(myTeamsPotentialAction2)
    team_message.addPotentialAction(myTeamsPotentialAction3)

    team_message.title('title')
    team_message.text('text')
    team_message.color(card_styles[level])

    team_message.send()

The OpenUri action does not show up (the other two actions showed up fine). What might be the cause?

Retain formatting of text (ie \n \t characters)

Describe the bug
Formatting / new lines / tabs are not retained.

To Reproduce

>>> body = "First line\nNewline\n\tTabbed in"
>>> message = pymsteams.connectorcard("https://example.com/")
>>> message.title("Test message, formatting")
>>> message.text(body)
>>> message.send()
True
>>> 

Result:
image

Expected behavior
I would have expected new lines, and tabs to be retained. I have sometimes, a large blob of JSON I'd like to print out as YAML since that's easier on the eyes, but it ends up just as unreadable. I've tried alternate carriage returns such as \r\n with the same result.

Appreciate any pointers you might have if I'm simply doing something silly here.


Edit:
I notice that there is some success with \r\n\r\n for new lines, but no luck with tabs; pretty sure this is outside the control of this project.

link button bug ?

image

myTeamsMessage.title("System Alert") myTeamsMessage.text("Description: Network error !!") myTeamsMessage.addLinkButton("Assign to me", "https://github.com/rveachkc/pymsteams/") myTeamsMessage.send()

when i keep sending same message ... y the button will keep increase ?

connector_card.send() sometimes returns True even when the message does not appear in the channel.

Describe the bug
connector_card.send() sometimes returns True even when the message does not appear in the channel. We have retry logic structure in place to attempt to send a message 3 times. Twice now, the connector_card.send() returned True but did not send a message to the Teams channel.

To Reproduce
Steps to reproduce the behavior:
Unable to consistently reproduce, but has happened at least twice.

Expected behavior
When connector_card.send() returns True, the message within the connector_card should show up in the appropriate teams channel.

Additional context
Our codebase uses a helper function to send a given message to a given channel_url. The channel_url is stored in config files. If the response from connector_card.send() is True, we return the response. If an Exception is thrown, we print the Exception and retry. See below:

connector_card = pymsteams.connectorcard(channel_url)
retry_count = self.retry_count
        while retry_count > 0:
            try:
                retry_count -= 1

                # Add text to the message.
                connector_card.text(message)
                # Send the message
                response = connector_card.send()

                if response:
                    celery_logger.info(f"Successfully sent update to Teams channel: {response}")
                    return response
                else:
                    celery_logger.info("Teams post_to_channel() failed to respond, retrying.")
            except Exception as inst:
                celery_logger.warning(f"Hit Exception during send(): {str(inst.args)}")
                print("...Hit Exception during send()!")
                print("\n" + str(inst.args) + "\n")
                continue
        return False

Validate message was received

Is there a way to check the response from the .send call to check that the message was posted into Teams without having to manually check?

Allow passing a json object from the Cards playgrounds

I understand that the whole point of the library is to provide a nice wrapper around building the payload but why not allow it to be passed or overriden ?

Maybe I am missing something but when I try to set the payload (which I got from a random https://amdesigner.azurewebsites.net/ design) by doing :

teams_msg = pymsteams.connectorcard(self.channel_url)
teams_msg.payload = {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "Container",
            "id": "4c2dc9a5-c7e3-47a4-bc91-0757cd2111df",
            "padding": "None",
            "items": [
                {
                    "type": "FactSet",
                    "id": "33ddcb61-e98f-6ca1-f966-b8297fef4a55",
                    "facts": [
                        {
                            "title": "Blah",
                            "value": "Blah"
                        },
                        {
                            "title": "Blah2",
                            "value": "Blah3"
                        }
                    ]
                },
                {
                    "type": "ColumnSet",
                    "id": "dcd32e4a-b929-f5bb-0baa-be2c05450912",
                    "columns": [
                        {
                            "type": "Column",
                            "id": "88bd4cc2-80f3-1529-7a44-a18481018ce9",
                            "padding": "None",
                            "width": "auto",
                            "items": [
                                {
                                    "type": "Input.Date",
                                    "id": "61b02780-cae1-f98c-105e-f11e9c74a9c1"
                                }
                            ]
                        }
                    ],
                    "padding": "None"
                }
            ]
        }
    ],
    "padding": "None"
}
teams_msg.text("test text")
teams_msg.send()

I get a regular message in the channel, not the one I had designed.
I had to add a text because otherwise it would fail with a 400 error (Summary or Text is required).

Is there a specific, more restrictive card playground that is compatible with Teams only maybe ?

Message not fully displayed

Describe the bug
I have a message with 20+ sections, and after sending the message to the teams, the message is collapsed. After clicking see more, only 10 of the sections are displayed. I am working on the macOS version of the teams.

The message gets fully displayed on the iOS though

Not getting expected response from connectorcard::send

Describe the bug
When the content of a message being sent is too large the message won't be posted to Teams, but send still return True.

To Reproduce
This seems to be caused by the amount of chars\bytes sent in the message.
I've repro'd it by forming card sections with bulleted strings of notes (between 48-52 chars).

  • Sending 200 lines (approx. 10,000 chars) works
  • Sending 500 lines (approx. 25,600 chars) won't send the message but still returns True from send

Expected behavior
I would like to get enough information from a bad http request so that if the message is too large to send, I can break it into multiple smaller messages that will send.

Images appear small

Images added using myMessageSection.addImage appear small regardless of resolution. Also attempting to use <img src=http://someimage.jpg></img> inside the activity text means it doesn't show at all. Any way to include larger images in the payload so they are visible? Otherwise I'll revert to just links

Direct Message Multiple Users

Is there a way to direct message multiple users?

E.G.:
Domain User A is logged in - runs the python script.
Then opens a "private" chat with Domain User B and Domain User C.

Add OpenURI functionality

OpenURI functionality is missing. This is abit of a caveat since it has it's own @type field independent of the @type of ActionCard

I was able to add the functionality with the python 3.6 code snippet below
`

def addOpenURI(self, _name: str, _targets: list):
    """
    Creates a OpenURI action

    https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#openuri-action

    :param _name: *Name of the text to appear inside the ActionCard*
    :type _name: str
    :param _targets: *A list of dictionaries, ex: {"os": "default", "uri": "https://www..."}*
    :type _targets: list(dict())
    """
    self.payload["@type"] = "OpenUri"
    self.payload["name"] = _name
    if not isinstance(_targets, list):
        raise TypeError("Target must be of type list(dict())")
    self.payload["targets"] = _targets

`

Feature to reply to a conversation in teams

I am reading data using outgoing webhook, and I get message id, channel id, etc from json data. I wish to send reply to a conversation instead of new message. Is this feature feasible ?

Suppressed error when 403 is returned

Whenever posting to a webhook results in a 403 Forbidden, this information is never presented and no TeamsWebhookException is thrown.

I've had a few projects running w/ pymsteams for a while, when suddenly one stopped working today. Nothing seemed to be wrong when running the script, so I started manually POSTing to the connector URL only to find that I was getting a 403 back.

Add Python 2 Support

"pip install pymsteams" installs version 0.1.3 :
Successfully installed pymsteams-0.1.3

"pip install pymsteams==0.1.7" fails
Collecting pymsteams==0.1.7 Could not find a version that satisfies the requirement pymsteams==0.1.7 (from versions: 0.1, 0.1.1, 0.1.2, 0.1.3) No matching distribution found for pymsteams==0.1.7

Button for shared file location

Hi, I am wondering if it is possible to link a file path on a shared drive to a button that shows up in my teams message?

Update message method

Hello,
is there a way to edit the text you have sent? For instance, I want to make something like

myTeamsMessage = pymsteams.connectorcard("<Microsoft Webhook URL>")

myTeamsPotentialAction1 = pymsteams.potentialaction(_name = "Add a comment")
myTeamsPotentialAction1.addInput("TextInput","comment","Add a comment here",False)
myTeamsPotentialAction1.addAction("HttpPost","Add Comment","https://...")

myTeamsPotentialAction2 = pymsteams.potentialaction(_name = "Set due date")
myTeamsPotentialAction2.addInput("DateInput","dueDate","Enter due date")
myTeamsPotentialAction2.addAction("HttpPost","save","https://...")

myTeamsPotentialAction3 = pymsteams.potentialaction(_name = "Change Status")
myTeamsPotentialAction3.choices.addChoices("In progress","0")
myTeamsPotentialAction3.choices.addChoices("Active","1")
myTeamsPotentialAction3.addInput("MultichoiceInput","list","Select a status",False)
myTeamsPotentialAction3.addAction("HttpPost","Save","https://...")

myTeamsMessage.addPotentialAction(myTeamsPotentialAction1)
myTeamsMessage.addPotentialAction(myTeamsPotentialAction2)
myTeamsMessage.addPotentialAction(myTeamsPotentialAction3)

myTeamsMessage.summary("Test Message")

myTeamsMessage.send()

I want a status box where I can choose between Active and Inactive and if I save it than the text changes to whatever I picked.
Is this possible?
Atleast here's the documentation
https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conversations

you'll need to get the conversationId

Make send method async-able

Hello,

I would like to connect send multiple messages, possibly to multiple Teams.
Is it possible to offer an alternative async send?

Question: Mentioning people

I am trying to send automated messages with pymsteams to a teams channel and it is working great, but I am wondering if it is possible to mention people in the message using their email address. I tried using "@[email protected]" but that didn't work. Does anyone have any experiences with this, or is it at all possible to do in Teams?

Proxy

My Internet connection must be through proxy. Is it possible to configure the proxy server to establish the connection to the webhook?
Thanks.

Enhancement Request - Add support for message summary

In many cases a header is not needed for the message - today webhooks require either text or summary property for each message.

using summary property allows to remove the header and the summary will not be shown.

class connectorcard:

def text(self, mtext):
	self.payload["text"] = mtext

def title(self, mtitle):
	self.payload["title"] = mtitle
	
def summary(self,msummary):
	self.payload["summary"] = msummary

convert JSON to pymsteams

Hello,
I tried converting following JSON into your pymsteams logic:
PICTURE

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "themeColor": "86bb0b",
    "summary": "Eingehende Ring Doorbell Benachrichtigung!",
    "sections": [{
        "activityTitle": "ACHTUNG!",
        "activitySubtitle": "von RealRing API v1",
        "activityImage": "data:image/jpeg;base64,/9j/4.....",
        "facts": [{
            "name": "Ort",
            "value": "%s"
        }, {
            "name": "Zeitpunkt",
            "value": "%s" 
            
        }],
        "markdown": true
    }],
    "potentialAction": [{
        "@type": "ActionCard",
        "name": "LIVESTREAM",
        "@type": "openUri",
         "targets": [
    { "os": "default", "uri": "https://f6f7a6ef2.ngrok.io/..." }

]
        
        
    
    }, {
        "@type": "ActionCard",
        "name": "Zutritt erlauben",
        "actions": [{
            "@type": "HttpPOST",
            "name": "Genehmigen",
            "target": "https://f6f76aef2.ngrok.io.....",
            "bodyContentType":"application/json",
            "body": '{
                "id" : "%s"
                }'
        }]
    }]
}

But somehow I cant figure out how I can remake this.
Just by the way, with this JSON i don't get the button which says "LIVESTREAM" on mobile phone so basically on mobile I can only see the button called "Zutritt erlauben", do you possibly know why?

thanks

Enhancement Request - Add Support for @Mentions

This code really makes it easy for us to integrate automated communications into our Teams Channels.

I would like to request @mentions be supported. We have various scenarios when we would like to tag/notify Associates of events. Supporting an @username tag/notification would really help us take Microsoft Teams to the next level.

@rveachkc let me know if this is not the Official Microsoft Repository for Teams. If it isn't I'll repost this request there.

Unable to send stylized msg using pandas

So i am trying to send an automated MSG to Microsoft Teams using pymsteams , I have a Dataframe on which i am applying certain logic an final df is something like this


a b c d
1 2 7 8
0 3 4 6
9 2 1 0

Now when i am sending to pymsteams like this it works

df=df.to_html()
web_hook = 'my_webhook'
myTeamsMessage = pymsteams.connectorcard(web_hook)
myTeamMessage.title("Today's Status")
myTeamsMessage.text("test")
myMessageSection = pymsteams.cardsection()
myMessageSection.title("test")
myMessageSection.text(df)
myTeamsMessage.addSection(myMessageSection)
myTeamsMessage.send()

Now i need to add a background color/text color to the table that is being generated according to some values for example -> all values > 5 should come as red . I tried to achieve this using

df=df.style.apply(custom_func)
df=df.render()
web_hook = 'my_webhook'
myTeamsMessage = pymsteams.connectorcard(web_hook)
myTeamMessage.title("Today's Status")
myTeamsMessage.text("test")
myMessageSection = pymsteams.cardsection()
myMessageSection.title("test")
myMessageSection.text(df)
myTeamsMessage.addSection(myMessageSection)
myTeamsMessage.send()

But this sends a blank message with just the title and section title , the data is not displayed , anyway i can achieve this? Any help or any pointer would be greatly appreciated

Enhancement Request - HTML Body

It would be really nice to display information in a message/channel card via html. This would allow users to display customized data frames and other information.

Potential Actions

If pull request was approved, please add this code example to the read me

`myTeamsPotentialAction1 = pymsteams.potentialaction(_name = "Add a comment")
myTeamsPotentialAction1.addInput("TextInput","comment","Add a comment here",False)
myTeamsPotentialAction1.addAction("HttpPost","Add Comment","http://...")

myTeamsPotentialAction2 = pymsteams.potentialaction(_name = "Set due date")
myTeamsPotentialAction2.addInput("DateInput","dueDate","Enter due date")
myTeamsPotentialAction2.addAction("HttpPost","save","https://...")

myTeamsPotentialAction3 = pymsteams.potentialaction(_name = "Change Status")
choices = [
{
"display": "In progress",
"value": "1"
},
{
"display": "Active",
"value": "2"
},
{
"display": "Closed",
"value": "3"
}]
myTeamsPotentialAction3.addInput("MultichoiceInput","list","Select a status",False,choices)
myTeamsPotentialAction3.addAction("HttpPost","Save","http://...")

myTeamsMessage.addPotentialAction(myTeamsPotentialAction1)
myTeamsMessage.addPotentialAction(myTeamsPotentialAction2)
myTeamsMessage.addPotentialAction(myTeamsPotentialAction3)

myTeamsMessage.summary("Test Message")

myTeamsMessage.send()`

Is it possible to post to specific Channels?

Have this working, awesome work thank you. Is it possible though to post to channels within a Team? Currently it just goes to the group in Outlook. Was hoping to get a message into a specific channel within a group

How to add data from a list of objects?

I have a list of objects getting data using an SQL query. Say contentList[] has the data and column names are "content text", "updated on", "trigger". How can I display this data using pymsteams if I pass the contentList[] in parameter of the function?

Readme: how to obtain connector webhook URL for you channel

Right now, it's possible to obtain connector webhook URL in a simplier way:

  • RMB on the channel
  • choose 'Connectors'
  • find and pick 'Incoming Webhook'

Perhaps you may point this out. Made life simplier for me.
P.S. I use Teams on corporate basis (without Office 365 subscription).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.