poshbotio / PoshBot

Powershell-based bot framework
MIT License
540 stars 108 forks source link

Utilizing Incoming Webhook in Middleware PreExecute Hook #219

Closed jcreo4299 closed 4 years ago

jcreo4299 commented 4 years ago

Background

I am working with the code provided in an earlier issue for sending a message regarding approvals in the pre-execute middleware hooks. The script provided works excellent, but due to Teams and not being able to mention people / channels through a webhook, we are trying to utilize normal incoming webhooks to send a message to another teams channel to notify users of a pending approval.

Expected Behavior

Pre-Execute processes the script and notifies the user on approval required while also sending out a message through the channel webhook to another Teams channel to alert of the pending approval.

Current Behavior

The user does not receive the message stating the command requires and approval but the webhook to the other Teams channel does receive the custom message. When running !pending, there are no pending commands in the queue.

Steps to Reproduce

Utilizing the code provided in #157 provided by devBlackOps, this works as provided.

Added a custom message card layout as shown below:

$approvalMessage = @" { "@type": "MessageCard", "@context": "https://schema.org/extensions", "summary": "ChatOps Command Approval", "themeColor": "D778D7", "title": "ChatOps Command Approval Required", "sections": [ {

            "facts": [
                {
                    "name": "User:",
                    "value": "USER_NAME"
                },
                {
                    "name": "Time:",
                    "value": "DATETIME"
                },
                {
                    "name": "Command:",
                    "value": "COMMANDRUN"}
            ],
            "text": "The user needs approval running the command listed above. Please use !Pending to approve."
        }
    ]
}

"@

Then upon utilizing Invoke-RestMethod to the URI for the webhook, the message sends but appears the Pre-Execute stops processing. This code was placed at the end of the script, below the line $Bot.LogInfo("Ending [PreExecute] hook"). I have also tried other various locations in the script with no success. The user never receives the requires approval message and never gets into the pending queue.

Your Environment

Windows Server 2019 Powershell v 5 Poshbot v 0.13.0

jcreo4299 commented 4 years ago

Was able to work around this by just modifying the main module PoshBot.psm1 which provided a solution to my problem above.