Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adaptive Cards in durable functions not sending correct message.

ZahlenZ opened this issue Β· comments

πŸ› Describe the bug
When utilizing adaptive cards in Azure Durable Functions, no matter what changes you make to the card throughout the durable function, it will always send the first card that was generated.

πŸ€” Expected behavior
Every time a new card is generated this card should be sent.

β˜• Steps to reproduce

What Durable Functions patterns are you using, if any?
Orchestration function calls activity function that sends posts an adaptive card to a Microsoft teams channel, after the activity function completes the orchestration function posts a different adaptive card to the same Microsoft teams channel.
Any minimal reproducer we can use?
ORCHESTRATION FUNCTION:

from sharedCode.AdaptiveCard import teams_notification


def orchestrator_function(context: df.DurableOrchestrationContext):

    result = yield context.call_activity("notification")
    
    payload = "This is from the orchestration function"
    teams_notification(payload=payload)

    return [result]


main = df.Orchestrator.create(orchestrator_function)

ACTIVITY FUNCTION:

from sharedCode.AdaptiveCard import teams_notification

def main(notification: list) -> int:
    
    payload = "This is from inside the notification function"
    
    teams_notification(payload=payload)    

    return ""

sharedCode.AdaptiveCard:
I have removed the URL to post to my teams channel

# url to post to microsoft teams
adaptive_card_url = "{insert a webhook url here}"
# card to post to microsoft teams
adaptive_card = {
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "contentUrl": None,
            "content": {
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "type": "AdaptiveCard",
                "version": "1.2",
                "body": [
                    {
                        "type": "TextBlock",
                        "text": "<at>Zahlen Zbinden</at>"
                    },
                    {"type": "TextBlock", "text": "Message: {message}", "wrap": True},
                ],
                "msteams": {
                    "width": "Full",
                    "entities": [
                        {
                            "type": "mention",
                            "text": "<at>Zahlen Zbinden</at>",
                            "mentioned": {
                                "id": "zahlen.zbinden@coldist.com",
                                "name": "Zahlen Zbinden",
                            },
                        }
                    ],
                },
            },
        }
    ],
}


def teams_notification(payload, base_card=adaptive_card, url=adaptive_card_url):
    headers = {"Content-Type": "application/json"}

    base_card["attachments"][0]["content"]["body"][1]["text"] = base_card[
        "attachments"
    ][0]["content"]["body"][1]["text"].format(message=payload)

    try:
        r = requests.post(url=url, data=json.dumps(base_card), headers=headers)
        test = "im here"
    except Exception as er:
        logger.exception(
            f"Failed to send teams notification. \n\n\
            ERROR: {str(er)}. \n\n\
            TRACEBACK: {traceback.format_exc()}"
        )
        raise er

With the code above it calls the activity function and sends the card with message: "This is from inside the notification function", it then goes into the orchestration where it should send the message: "this is from the orchestration function" however it sends the message "this is from inside the notification function"

Are you running this locally or on Azure?
Locally and in Azure have the same outcome. This behavior continues through multiple instances of the orchestration. i.e. when you run the orchestration for the first time and it sends notification card with message "this is run one". then you stop the orchestration and change the notification card to send "this is run two" the card will still send "this is run one". In Azure the only way to get the card to update is to restart the application. On the local you have to clear the storage emulators.

⚑If deployed to Azure

We have access to a lot of telemetry that can help with investigations. Please provide as much of the following information as you can to help us investigate!

Only going to include the 2 most recent runs, I only noticed this in the last week, and it has been persistent since I first noticed it.

  • Timeframe issue observed: 12:02 AM PST 9/15/2023, 6:55AM PST 9/15/2023 (both of these times are from runs in Azure that completed) I just ran it again right now, the process takes around an hour, so I can't give you the exact time it will complete but somewhere around 10:15AM PST with orchestration instance "id": "1a8fc459460c46ed88965e11bb778dc6"
  • Function App name: coldist-integrations-uat-wus2-adpapi-dfunc
  • Function name(s): LoadEDW
  • Azure region: west us 2
  • Orchestration instance ID(s): 1a8fc459460c46ed88965e11bb778dc6
  • Azure storage account name: coldistintegrationsbf07