rveachkc / pymsteams

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

HttpPost - Failed to send - Could not complete the requested action. Please try again later. [CODE INCLUDED] #106

Closed marfiska closed 3 years ago

marfiska commented 3 years ago

Hello! I'm new to this project and I'm wrapping up the last bit of an API I'm putting together. The HTTP post is not working but I suspect I'm missing something. Please see below for my code. I get the card with all the relevant information, but when the button is clicked, it's unsuccessful.

In the below example, localhost:5000/alert/camera is the same API that I'm calling, I'm just trying to invoke it again through the button to validate it works. Any help is greatly appreciated!

Building MS Teams card

card = pymsteams.connectorcard(payload['eventWebhook'])

Add buttons and actions

AcknowledgeAction = pymsteams.potentialaction(_name = "Acknowledge") AcknowledgeAction.addAction("HttpPost","Send Update","https://localhost:5000/alert/camera")

ResetAction = pymsteams.potentialaction(_name = "Suppress Alerts") ResetAction.addAction("HttpPost","Suppress","https://localhost:5000/alert/camera") ResetAction.choices.addChoices("30 minutes","30") ResetAction.choices.addChoices("1 hour","60") ResetAction.choices.addChoices("4 hours","240") ResetAction.choices.addChoices("8 hours","540") ResetAction.choices.addChoices("24 hours","1440") ResetAction.addInput("MultichoiceInput","list","Suppress alerts for",False)

Section and attributes of card

Section = pymsteams.cardsection() Section.title(f"Application : {payload['application']}") Section.activityTitle(f"Alerted on : {payload['eventTime']}") Section.addFact("Image name :", payload['imageName']) Section.addFact("Results :", payload['results']) Section.addFact("Event Position : ", payload['eventPosition']) Section.addFact("Events in last 24/hrs :", payload['eventHistory']) Section.addImage(f"{payload['imageUrl']}")

Add to card

card.addSection(Section) card.addPotentialAction(AcknowledgeAction) card.addPotentialAction(ResetAction) card.addLinkButton("View raw image", payload['imageUrl'])

Send action

card.send() app.logger.info(payload)

rveachkc commented 3 years ago

Microsoft Teams requires that you use a url that is available over the internet. You would need to expose this endpoint, and call it through the public url.

From the Microsoft documentation (https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#httppost-action):

Defines the URL endpoint of the service that implements the action. Note: this URL must be accessible from the internet, you cannot use localhost.