创建线程
本文内容
命名空间:microsoft.graph
在指定会话中创建新线程。
按指定方式创建线程和帖子。使用 回复线程 进一步发布到该线程。或者,如果你获得帖子 ID,还可以在该线程中 回复 帖子。
注意:还可以 通过首先创建一个线程启动一个新的对话
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Group.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
不支持。
HTTP 请求
POST /groups/{id}/conversations/{id}/threads
名称
说明
Authorization
Bearer {token}。必需。
请求正文
在请求正文中,提供 ConversationThread 对象的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 conversationThread 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/v1.0/groups/{id}/conversations/{id}/threads
Content-type: application/json
{
"topic": "Take your wellness days and rest",
"posts": [
{
"body": {
"contentType": "html",
"content": "Waiting for the summer holidays."
}
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var conversationThread = new ConversationThread
{
Topic = "Take your wellness days and rest",
Posts = new ConversationThreadPostsCollectionPage()
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Waiting for the summer holidays."
}
}
}
};
await graphClient.Groups["{group-id}"].Conversations["{conversation-id}"].Threads
.Request()
.AddAsync(conversationThread);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const conversationThread = {
topic: 'Take your wellness days and rest',
posts: [
{
body: {
contentType: 'html',
content: 'Waiting for the summer holidays.'
}
}
]
};
await client.api('/groups/{id}/conversations/{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}/conversations/{id}/threads"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversationThread *conversationThread = [[MSGraphConversationThread alloc] init];
[conversationThread setTopic:@"Take your wellness days and rest"];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Waiting for the summer holidays."];
[posts setBody:body];
[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 = "Take your wellness days and rest";
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Waiting for the summer holidays.";
posts.body = body;
postsList.add(posts);
PostCollectionResponse postCollectionResponse = new PostCollectionResponse();
postCollectionResponse.value = postsList;
PostCollectionPage postCollectionPage = new PostCollectionPage(postCollectionResponse, null);
conversationThread.posts = postCollectionPage;
graphClient.groups("{id}").conversations("{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 := "Take your wellness days and rest"
requestBody.SetTopic(&topic)
requestBody.SetPosts( []Post {
msgraphsdk.NewPost(),
body := msgraphsdk.NewItemBody()
SetBody(body)
contentType := "html"
body.SetContentType(&contentType)
content := "Waiting for the summer holidays."
body.SetContent(&content)
}
groupId := "group-id"
conversationId := "conversation-id"
result, err := graphClient.GroupsById(&groupId).ConversationsById(&conversationId).Threads().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Groups
$params = @{
Topic = "Take your wellness days and rest"
Posts = @(
@{
Body = @{
ContentType = "html"
Content = "Waiting for the summer holidays."
}
}
)
}
New-MgGroupConversationThread -GroupId $groupId -ConversationId $conversationId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
在请求正文中,提供 ConversationThread 对象的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和新线程的 id。
下面展示了示例响应。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('4d81ce71-486c-41e9-afc5-e41bf2d0722a')/conversations('AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgAQABKPPJ682apIiV1UFlj7XxY%3D')/threads/$entity",
"id": "AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgMkABAArnv4XDMi_kemtqM1d730TxAArnv4XDMi_kemtqM1d730Tw=="
}