spacer
Skip to content

Graph Conversations

More information can be found in the official Graph documentation:

IConversation, IConversations, IPost, IPostForwardInfo, IPosts, ISenders, IThread, IThreads

Invokable Banner Selective Imports Banner

Get Group Accepted/Rejected Senders

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const accepted = await graph.groups.getById(groupId).acceptedSenders();
const rejected = await graph.groups.getById(groupId).rejectedSenders();

Add Group Accepted/Rejected Senders

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const sender = "https://graph.microsoft.com/v1.0/users/user@contoso.com";
await graph.groups.getById(groupId).acceptedSenders.add(sender);
await graph.groups.getById(groupId).rejectedSenders.add(sender);

Delete Group Accepted/Rejected Senders

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const sender = "https://graph.microsoft.com/v1.0/users/user@contoso.com";
await graph.groups.getById(groupId).acceptedSenders.remove(sender);
await graph.groups.getById(groupId).rejectedSenders.remove(sender);

Get Group Conversations

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const c = await graph.groups.getById(groupId).conversations();

Get Group Conversation by Id

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const conversationId = "";
const c = await graph.groups.getById(groupId).conversations.getById(conversationId)();

Add/Update/Delete a Group Conversation

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { Conversation } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const conversation: Conversation = {
  topic: "My New Conversation",
  ...
};

const c = await graph.groups.getById(groupId).conversations.add(conversation);

const conversationId = "";
const update = await graph.groups.getById(groupId).conversations.getById(conversationId)
    .update({topic: "My Conversation"});
await graph.groups.getById(groupId).conversations.getById(conversationId).delete();

Get Group Conversation Threads

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { Conversation } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const groupId = "";
const conversationId = "";
const t = await graph.groups.getById(groupId).conversations.getById(conversationId).threads();

Get Group Conversation Thread by Id

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const conversationId = "";
const threadId = "";
const c = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId)();

Create/Update/Delete a Group Conversation Thread

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { ConversationThread } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const conversationThread: ConversationThread = {
  topic: "My New Conversation",
  ...
};

const conversationId = "";
const t = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.add(conversationThread);

const threadId = "";
const update = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId)
    .update({topic: "My Conversation"});
await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).delete();

Reply to a Group Conversation Thread

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { Post } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const post: Post = {
    body: { content: "This is a post" },
    from: {
        emailAddress: {
            address: "",
            name: "",
        },
    },
};

const conversationId = "";
const threadId = "";
const reply = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).reply(post);

Get Group Conversation Thread Posts

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const groupId = "";
const conversationId = "";
const threadId = "";
const p = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts();

Get Group Conversation Thread Post by Id

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";

const graph = graphfi(...);

const conversationId = "";
const threadId = "";
const postId = "";
const p = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.getById(postId)();

Create/Update/Delete a Group Conversation Thread Post

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { Post } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const post: Post = {
    body: { content: "This is a post" },
    from: {
        emailAddress: {
            address: "",
            name: "",
        },
    },
};

const conversationId = "";
const threadId = "";
const p = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.add(post);

const postId = "";
const update = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.getById(postId)
    .update({body: {content: "New Post Content"}});
await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.getById(postId).delete();

Reply to a Group Conversation Thread Post

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { Post } from "@microsoft/microsoft-graph-types";

const graph = graphfi(...);

const post: Post = {
    body: { content: "This is a post" },
    from: {
        emailAddress: {
            address: "",
            name: "",
        },
    },
};

const conversationId = "";
const threadId = "";
const reply = await graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.getById(postId).reply(post);

Forward a Group Conversation Thread Post

import { graphfi } from "@pnp/graph";
import "@pnp/graph/groups";
import "@pnp/graph/conversations";
import { IPostForwardInfo } from "@pnp/graph/conversations";

const graph = graphfi(...);

const postForwardInfo: IPostForwardInfo = {
    toRecipients: [
        {
            emailAddress: {
                address: "",
                name: "",
            },
        },
    ],
};

const conversationId = "";
const threadId = "";
const post = graph.groups.getById(groupId).conversations.getById(conversationId).threads.getById(threadId).posts.getById(postId);
await post.forward(postForwardInfo);

Group Conversation Thread Post Attachments

See Attachments