rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
422 stars 78 forks source link

Every time a new message is sent, another button gets added to the message. #92

Closed cschreiberBES closed 3 years ago

cschreiberBES commented 3 years ago

Hello,

I have a function that sends a message to a MS Teams channel every time it is called. The first call, the message sends correctly and only contains 1 button. Every time the function is called after that, another button gets added to the message.

My Function:

def sendToMSTeams (speed, name, driveTime, distance, scName):
    title = 'Driver ETA Alert - {0} Minutes from {1} Processing Center'.format(driveTime, scName)
    text = '{0} is {1} miles away from the {2} processing center. They will arrive in {3} Minutes. They are currently traveling at {4} MPH.'.format(name , str(distance), scName, str(driveTime), str(speed))
    btnText = "View on Map"
    btnURL = "https://www.google.com/"
    msTeamsConnection.title(title)
    msTeamsConnection.text(text)
    msTeamsConnection.addLinkButton(btnText, btnURL)
    msTeamsConnection.send()

Expected behavior I expect that, for every message sent, only one button displays on the message.

Screenshots image

Please let me know if this is a genuine bug, or I am just missing something.

Thank you!

rveachkc commented 3 years ago

This happens because the entire message persists, including the text, title, buttons, etc.

The addLinkButton appends a new button instead of replacing it.

You don't see the same behavior with the other elements, because they are simply overwritten.

The connector card object represents a message, not a connection. You should create a new one for every message you send.

cschreiberBES commented 3 years ago

Thanks @rveachkc for the help! I will give that a try.