Add-On for Microsoft Teams and Gravity Forms

The Add-On for Microsoft Teams and Gravity Forms plugin has a useful hook for developers to use to further enhance its functionality.

ms_teams_data_args

TYPE ⇢ Filter

This filter allows developers to modify or override the message payload sent when a Gravity Form entry is submitted to Microsoft Teams. It allows for adjustments to the embed content, including custom buttons, title, description, colors, and attachments before sending the data. You can learn more about the structure and play around with the Adaptive Card Designer here: https://adaptivecards.io/designer/

Structure of $data:

PHP
$data = [
    'attachments' => [  // Attachments array contains all the visual and interactive content.
        [
            'contentType' => 'application/vnd.microsoft.card.adaptive',  // Type of card content
            'content'     => [  // Content of the Adaptive Card
                'type'    => 'AdaptiveCard',  // The card type
                'body'    => [  // The body of the card contains the main message content
                    [
                        'type'   => 'TextBlock',  // Title block
                        'size'   => 'ExtraLarge',  // Text size
                        'weight' => 'Bolder',  // Text weight (Bold)
                        'text'   => 'Form Submission Title'  // Title text (can be modified)
                    ],
                    [
                        'type'   => 'ColumnSet',  // Set of columns for layout
                        'columns' => [  // Column array
                            [
                                'type'  => 'Column',  // First column
                                'items' => [
                                    [
                                        'type'    => 'Image',  // Image element
                                        'url'     => 'site_logo_url',  // Logo URL
                                        'altText' => 'Site Name Logo',  // Alt text for the image
                                        'size'    => 'Small'  // Image size
                                    ]
                                ],
                                'width' => 'auto'  // Width of the column
                            ],
                            [
                                'type'  => 'Column',  // Second column
                                'items' => [
                                    [
                                        'type'   => 'TextBlock',  // TextBlock (site name)
                                        'weight' => 'Bolder',  // Bolder text
                                        'text'   => 'Site Name',  // Site name text
                                        'wrap'   => true  // Allow wrapping of text
                                    ],
                                    [
                                        'type'     => 'TextBlock',  // Timestamp
                                        'spacing'  => 'None',  // No spacing between elements
                                        'text'     => 'Submission Time',  // Submission time
                                        'isSubtle' => true,  // Make text subtle (lighter)
                                        'wrap'     => true  // Allow wrapping of text
                                    ]
                                ],
                                'width' => 'stretch'  // Stretch column to take available space
                            ]
                        ]
                    ],
                    [
                        'type' => 'TextBlock',  // Main message body
                        'text' => 'Message Content',  // Main message content (can be replaced dynamically)
                        'wrap' => true  // Wrap text for readability
                    ],
                    [
                        'type'  => 'FactSet',  // FactSet block for additional information (key-value pairs)
                        'facts' => [  // Array of facts (e.g., form field data)
                            [
                                'title'   => 'Field Title',  // Key/Field name
                                'value'   => 'Field Value'   // Corresponding value
                            ]
                            // Additional facts can be added here...
                        ]
                    ]
                ],
                'actions' => [  // Actions (interactive buttons)
                    // Example buttons (for visiting URLs, viewing entries, etc.)
                    [
                        'type'  => 'Action.OpenUrl',  // Button type (open URL)
                        'title' => 'View Entry',  // Button title
                        'url'   => 'https://example.com/view-entry'  // URL to open
                    ]
                ],
                'msteams' => [
                    'width' => 'Full'  // Ensure the action buttons span full width
                ],
                '$schema' => 'http://adaptivecards.io/schemas/adaptive-card.json',  // Schema URL for validation
                'version' => '1.4'  // Adaptive card version
            ]
        ]
    ]
];

Example Usage

PHP
/**
 * Modify MS Teams message data before sending.
 *
 * @param array  $data   The current message data to be sent.
 * @param array  $form   The Gravity Forms form object.
 * @param array  $entry  The Gravity Forms entry object.
 *
 * @return array The modified message data to be sent.
 */
add_filter( 'ms_teams_data_args', function( $data, $form, $entry ) {
    // Example: Modify the title based on the form ID
    if ( $form[ 'id' ] === 1 ) {
        $data[ 'attachments' ][0][ 'content' ][ 'body' ][0][ 'text' ] = 'Custom Title for Form 1';
    }

    // Add custom button
    $data[ 'attachments' ][0][ 'content' ][ 'actions' ][] = [
        'type'  => 'Action.OpenUrl',
        'title' => 'Visit Site',
        'url'   => home_url()
    ];

    return $data;
}, 10, 3 );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.