创建对话线程
本文内容
命名空间:microsoft.graph
首先,通过创建线程来启动新的组对话。
创建新会话、会话线程,然后可在组中创建帖子。使用 回复线程 或 回复帖子 进一步发布到该线程。
注意:你还可以 在现有会话中启动新线程 。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Group.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
Application
不支持。
HTTP 请求
POST /groups/{id}/threads
标头
值
Authorization
Bearer {token}。必需。
Content-Type
application/json
请求正文
在请求正文中,提供代表包括 帖子 的 conversationThread 的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 conversationThread 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/v1.0/groups/{id}/threads
Content-type: application/json
{
"topic": "New Conversation Thread Topic",
"posts": [{
"body": {
"contentType": "html",
"content": "this is body content"
},
"newParticipants": [{
"emailAddress": {
"name": "Alex Darrow",
"address": "alexd@contoso.com"
}
}]
}]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var conversationThread = new ConversationThread
{
Topic = "New Conversation Thread Topic",
Posts = new ConversationThreadPostsCollectionPage()
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "this is body content"
},
NewParticipants = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Alex Darrow",
Address = "alexd@contoso.com"
}
}
}
}
}
};
await graphClient.Groups["{group-id}"].Threads
.Request()
.AddAsync(conversationThread);
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var conversationThread = new ConversationThread
{
Topic = "New Conversation Thread Topic",
Posts = new ConversationThreadPostsCollectionPage()
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "this is body content"
},
NewParticipants = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Alex Darrow",
Address = "alexd@contoso.com"
}
}
}
}
}
};
await graphClient.Groups["{group-id}"].Threads
.Request()
.AddAsync(conversationThread);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const conversationThread = {
topic: 'New Conversation Thread Topic',
posts: [{
body: {
contentType: 'html',
content: 'this is body content'
},
newParticipants: [{
emailAddress: {
name: 'Alex Darrow',
address: 'alexd@contoso.com'
}
}]
}]
};
await client.api('/groups/{id}/threads')
.post(conversationThread);
const options = {
authProvider,
};
const client = Client.init(options);
const conversationThread = {
topic: 'New Conversation Thread Topic',
posts: [{
body: {
contentType: 'html',
content: 'this is body content'
},
newParticipants: [{
emailAddress: {
name: 'Alex Darrow',
address: 'alexd@contoso.com'
}
}]
}]
};
await client.api('/groups/{id}/threads')
.post(conversationThread);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/{id}/threads"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversationThread *conversationThread = [[MSGraphConversationThread alloc] init];
[conversationThread setTopic:@"New Conversation Thread Topic"];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"this is body content"];
[posts setBody:body];
NSMutableArray *newParticipantsList = [[NSMutableArray alloc] init];
MSGraphRecipient *newParticipants = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setName:@"Alex Darrow"];
[emailAddress setAddress:@"alexd@contoso.com"];
[newParticipants setEmailAddress:emailAddress];
[newParticipantsList addObject: newParticipants];
[posts setNewParticipants:newParticipantsList];
[postsList addObject: posts];
[conversationThread setPosts:postsList];
NSError *error;
NSData *conversationThreadData = [conversationThread getSerializedDataWithError:&error];
[urlRequest setHTTPBody:conversationThreadData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/{id}/threads"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversationThread *conversationThread = [[MSGraphConversationThread alloc] init];
[conversationThread setTopic:@"New Conversation Thread Topic"];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"this is body content"];
[posts setBody:body];
NSMutableArray *newParticipantsList = [[NSMutableArray alloc] init];
MSGraphRecipient *newParticipants = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setName:@"Alex Darrow"];
[emailAddress setAddress:@"alexd@contoso.com"];
[newParticipants setEmailAddress:emailAddress];
[newParticipantsList addObject: newParticipants];
[posts setNewParticipants:newParticipantsList];
[postsList addObject: posts];
[conversationThread setPosts:postsList];
NSError *error;
NSData *conversationThreadData = [conversationThread getSerializedDataWithError:&error];
[urlRequest setHTTPBody:conversationThreadData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ConversationThread conversationThread = new ConversationThread();
conversationThread.topic = "New Conversation Thread Topic";
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "this is body content";
posts.body = body;
LinkedList<Recipient> newParticipantsList = new LinkedList<Recipient>();
Recipient newParticipants = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Alex Darrow";
emailAddress.address = "alexd@contoso.com";
newParticipants.emailAddress = emailAddress;
newParticipantsList.add(newParticipants);
posts.newParticipants = newParticipantsList;
postsList.add(posts);
PostCollectionResponse postCollectionResponse = new PostCollectionResponse();
postCollectionResponse.value = postsList;
PostCollectionPage postCollectionPage = new PostCollectionPage(postCollectionResponse, null);
conversationThread.posts = postCollectionPage;
graphClient.groups("{id}").threads()
.buildRequest()
.post(conversationThread);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ConversationThread conversationThread = new ConversationThread();
conversationThread.topic = "New Conversation Thread Topic";
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "this is body content";
posts.body = body;
LinkedList<Recipient> newParticipantsList = new LinkedList<Recipient>();
Recipient newParticipants = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Alex Darrow";
emailAddress.address = "alexd@contoso.com";
newParticipants.emailAddress = emailAddress;
newParticipantsList.add(newParticipants);
posts.newParticipants = newParticipantsList;
postsList.add(posts);
PostCollectionResponse postCollectionResponse = new PostCollectionResponse();
postCollectionResponse.value = postsList;
PostCollectionPage postCollectionPage = new PostCollectionPage(postCollectionResponse, null);
conversationThread.posts = postCollectionPage;
graphClient.groups("{id}").threads()
.buildRequest()
.post(conversationThread);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewConversationThread()
topic := "New Conversation Thread Topic"
requestBody.SetTopic(&topic)
requestBody.SetPosts( []Post {
msgraphsdk.NewPost(),
body := msgraphsdk.NewItemBody()
SetBody(body)
contentType := "html"
body.SetContentType(&contentType)
content := "this is body content"
body.SetContent(&content)
SetNewParticipants( []Recipient {
msgraphsdk.NewRecipient(),
SetAdditionalData(map[string]interface{}{
}
}
}
groupId := "group-id"
result, err := graphClient.GroupsById(&groupId).Threads().Post(requestBody)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewConversationThread()
topic := "New Conversation Thread Topic"
requestBody.SetTopic(&topic)
requestBody.SetPosts( []Post {
msgraphsdk.NewPost(),
body := msgraphsdk.NewItemBody()
SetBody(body)
contentType := "html"
body.SetContentType(&contentType)
content := "this is body content"
body.SetContent(&content)
SetNewParticipants( []Recipient {
msgraphsdk.NewRecipient(),
SetAdditionalData(map[string]interface{}{
}
}
}
groupId := "group-id"
result, err := graphClient.GroupsById(&groupId).Threads().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Groups
$params = @{
Topic = "New Conversation Thread Topic"
Posts = @(
@{
Body = @{
ContentType = "html"
Content = "this is body content"
}
NewParticipants = @(
@{
EmailAddress = @{
Name = "Alex Darrow"
Address = "alexd@contoso.com"
}
}
)
}
)
}
New-MgGroupThread -GroupId $groupId -BodyParameter $params
Import-Module Microsoft.Graph.Groups
$params = @{
Topic = "New Conversation Thread Topic"
Posts = @(
@{
Body = @{
ContentType = "html"
Content = "this is body content"
}
NewParticipants = @(
@{
EmailAddress = @{
Name = "Alex Darrow"
Address = "alexd@contoso.com"
}
}
)
}
)
}
New-MgGroupThread -GroupId $groupId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"toRecipients": [
{
"emailAddress": {
"name": "name-value",
"address": "address-value"
}
}
],
"topic": "topic-value",
"hasAttachments": true,
"lastDeliveredDateTime": "datetime-value",
"uniqueSenders": [
"uniqueSenders-value"
],
"ccRecipients": [
{
"emailAddress": {
"name": "name-value",
"address": "address-value"
}
}
]
}