chat: sendActivityNotification

Namespace: microsoft.graph

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

Send an activity feed notification in the scope of a chat. For more information, see sending Teams activity notifications.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) TeamsActivity.Send Not available.
Delegated (personal Microsoft account) Not supported. Not supported.
Application TeamsActivity.Send.Chat TeamsActivity.Send

Note: The TeamsActivity.Send.Chat permission uses resource-specific consent.

HTTP request

POST /chats/{chatId}/sendActivityNotification

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
Content-Type application/json. Required.

Request body

In the request body, supply JSON representation of the parameters.

The following table shows the parameters that can be used with this action.

Parameter Type Description
topic teamworkActivityTopic The topic of the notification. Specifies the resource being talked about.
activityType String The activity type must be declared in the Teams app manifest, except for the systemDefault Reserved activity type, which provides free-form text in the Actor+Reason line of the notification.
chainId Int64 Optional. The chain ID of the notification. Used to override a previous notification. Use the same chainId in subsequent requests to override the previous notification.
previewText itemBody The preview text for the notification. Microsoft Teams only shows the first 150 characters.
templateParameters keyValuePair collection The values for the template variables defined in the activity feed entry corresponding to activityType in the Teams app manifest.
recipient teamworkNotificationRecipient The recipient of the notification. For more information, see aadUserNotificationRecipient and chatMembersNotificationRecipient.
teamsAppId String Optional. The Teams app ID of the Teams app associated with the notification. Used to disambiguate installed apps when multiple apps with the same Microsoft Entra ID app ID are installed for the same recipient user. Avoid sharing Microsoft Entra ID app IDs between Teams apps.

The following resources are supported when setting the source value of the topic property to entityURL:

Note: The entity URL must be the same as the child resource of the chat in the URL. Additionally, the Teams app must be installed in the chat.

Response

If successful, this action returns a 204 No Content response code.

Examples

Example 1: Notify a user about a task created in a chat

The following example shows how you can send an activity feed notification for a new task created in a chat. For more information, see sending Teams activity notifications.

Request

The following example shows the request.

POST https://graph.microsoft.com/beta/chats/{chatId}/sendActivityNotification
Content-Type: application/json

{
    "topic": {
        "source": "entityUrl",
        "value": "https://graph.microsoft.com/beta/chats/{chatId}"
    },
    "activityType": "taskCreated",
    "previewText": {
        "content": "New Task Created"
    },
    "recipient": {
        "@odata.type": "microsoft.graph.aadUserNotificationRecipient",
        "userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
    },
    "templateParameters": [
        {
            "name": "taskId",
            "value": "Task 12322"
        }
    ] 
}

Response

The following example shows the response.

HTTP/1.1 204 No Content

Example 2: Notify a user about an approval needed in a chat message

Similar to the previous example, this example uses entityUrl for the topic. However, in this case, it links to a message in the chat. The message can contain a card with the approval button on it.

Request

The following example shows the request.

POST https://graph.microsoft.com/beta/chats/{chatId}/sendActivityNotification
Content-Type: application/json

{
    "topic": {
        "source": "entityUrl",
        "value": "https://graph.microsoft.com/beta/chats/{chatId}/messages/{messageId}"
    },
    "activityType": "approvalRequired",
    "previewText": {
        "content": "Deployment requires your approval"
    },
    "recipient": {
        "@odata.type": "microsoft.graph.aadUserNotificationRecipient",
        "userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
    },
    "templateParameters": [
        {
            "name": "approvalTaskId",
            "value": "2020AAGGTAPP"
        }
    ]
}

Response

The following example shows the response.

HTTP/1.1 204 No Content

Example 3: Notify a user about an approval needed in a chat message using the user's principal name

Similar to the previous example, this example uses entityUrl for the topic. However, in this case, it links to a message in the chat. The message can contain a card with the approval button on it.

Request

The following example shows the request.

POST https://graph.microsoft.com/beta/chats/{chatId}/sendActivityNotification
Content-Type: application/json

{
    "topic": {
        "source": "entityUrl",
        "value": "https://graph.microsoft.com/beta/chats/{chatId}/messages/{messageId}"
    },
    "activityType": "approvalRequired",
    "previewText": {
        "content": "Deployment requires your approval"
    },
    "recipient": {
        "@odata.type": "microsoft.graph.aadUserNotificationRecipient",
        "userId": "jacob@contoso.com"
    },
    "templateParameters": [
        {
            "name": "approvalTaskId",
            "value": "2020AAGGTAPP"
        }
    ]
}

Response

The following example shows the response.

HTTP/1.1 204 No Content

Example 4: Notify a user about an event about a chat

As shown in the previous examples, you can link to different aspects of the chat. However, if you want to link to an aspect that isn't part of the chat or isn't represented by Microsoft Graph, you can set the source of the topic to text and pass in a custom value. Also, webUrl is required when setting topic source to text.

Request

The following example shows the request.

POST https://graph.microsoft.com/beta/chats/{chatId}/sendActivityNotification
Content-Type: application/json

{
    "topic": {
        "source": "text",
        "value": "Deployment Approvals Channel",
        "webUrl": "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000"
    },
    "activityType": "deploymentApprovalRequired",
    "previewText": {
        "content": "New deployment requires your approval"
    },
    "recipient": {
        "@odata.type": "microsoft.graph.aadUserNotificationRecipient",
        "userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
    },
    "templateParameters": [
        {
            "name": "deploymentId",
            "value": "6788662"
        }
    ]
}

Response

The following example shows the response.

HTTP/1.1 204 No Content

Example 5: Notify the chat members about a task created in a chat

The following example shows how you can send an activity feed notification to all chat members. This example is similar to previous examples. However, in this case, the recipient is a chatMembersNotificationRecipient. The chatId specified in the recipient must match the chatId specified in the request URL.

Request

The following example shows the request.

POST https://graph.microsoft.com/beta/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2/sendActivityNotification
Content-Type: application/json

{
    "topic": {
        "source": "entityUrl",
        "value": "https://graph.microsoft.com/beta/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
    },
    "activityType": "taskCreated",
    "previewText": {
        "content": "New Task Created"
    },
    "recipient": {
        "@odata.type": "microsoft.graph.chatMembersNotificationRecipient",
        "chatId": "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
    },
    "templateParameters": [
        {
            "name": "taskId",
            "value": "Task 12322"
        }
    ] 
}

Response

The following example shows the response.

HTTP/1.1 204 No Content