Créer une conversation
Article
05/12/2022
6 minutes de lecture
3 contributeurs
Dans cet article
Espace de noms : microsoft.graph Créez une conversation en incluant un thread et un billet.
Utilisez reply thread ou reply post pour continuer à publier dans cette conversation.
Autorisations
L’une des autorisations suivantes est nécessaire pour appeler cette API. Pour plus d’informations, notamment sur la façon de choisir les autorisations, voir Autorisations .
Type d’autorisation
Autorisations (de celle qui offre le plus de privilèges à celle qui en offre le moins)
Déléguée (compte professionnel ou scolaire)
Group.ReadWrite.All
Déléguée (compte Microsoft personnel)
Non prise en charge.
Application
Non prise en charge.
Requête HTTP
POST /groups/{id}/conversations
En-tête
Valeur
Autorisation
Porteur {token}. Obligatoire.
Content-Type
application/json
Corps de la demande
Dans le corps de la demande, fournissez une représentation JSON de l’objet conversation contenant un conversationThread et un billet .
Réponse
Si elle réussit, cette méthode renvoie un code de réponse 201 Created
et un objet conversation dans le corps de la réponse.
La réponse inclut l’ID de la nouvelle conversation et du thread, que vous pouvez utiliser dans l’opération list posts pour obtenir le nouveau billet.
Exemple
Demande
Voici un exemple de demande.
POST https://graph.microsoft.com/v1.0/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations
Content-type: application/json
{
"topic": "Take your wellness days and rest",
"threads": [
{
"posts": [
{
"body": {
"contentType": "html",
"content": "Contoso cares about you: Rest and Recharge"
},
"newParticipants": [
{
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV@contoso.onmicrosoft.com"
}
}
]
}
]
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var conversation = new Conversation
{
Topic = "New locations for this quarter",
Threads = new ConversationThreadsCollectionPage()
{
new ConversationThread
{
Posts = new ConversationThreadPostsCollectionPage()
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "What do we know so far?"
},
NewParticipants = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Adele Vance",
Address = "AdeleV@contoso.onmicrosoft.com"
}
}
}
}
}
}
}
};
await graphClient.Groups["{group-id}"].Conversations
.Request()
.AddAsync(conversation);
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
const options = {
authProvider,
};
const client = Client.init(options);
const conversation = {
topic: 'Take your wellness days and rest',
threads: [
{
posts: [
{
body: {
contentType: 'html',
content: 'Contoso cares about you: Rest and Recharge'
},
newParticipants: [
{
emailAddress: {
name: 'Adele Vance',
address: 'AdeleV@contoso.onmicrosoft.com'
}
}
]
}
]
}
]
};
await client.api('/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations')
.post(conversation);
const options = {
authProvider,
};
const client = Client.init(options);
const conversation = {
topic: 'Take your wellness days and rest',
threads: [
{
posts: [
{
body: {
contentType: 'html',
content: 'Contoso cares about you: Rest and Recharge'
},
newParticipants: [
{
emailAddress: {
name: 'Adele Vance',
address: 'AdeleV@contoso.onmicrosoft.com'
}
}
]
}
]
}
]
};
await client.api('/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations')
.post(conversation);
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversation *conversation = [[MSGraphConversation alloc] init];
[conversation setTopic:@"Take your wellness days and rest"];
NSMutableArray *threadsList = [[NSMutableArray alloc] init];
MSGraphConversationThread *threads = [[MSGraphConversationThread alloc] init];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Contoso cares about you: Rest and Recharge"];
[posts setBody:body];
NSMutableArray *newParticipantsList = [[NSMutableArray alloc] init];
MSGraphRecipient *newParticipants = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setName:@"Adele Vance"];
[emailAddress setAddress:@"AdeleV@contoso.onmicrosoft.com"];
[newParticipants setEmailAddress:emailAddress];
[newParticipantsList addObject: newParticipants];
[posts setNewParticipants:newParticipantsList];
[postsList addObject: posts];
[threads setPosts:postsList];
[threadsList addObject: threads];
[conversation setThreads:threadsList];
NSError *error;
NSData *conversationData = [conversation getSerializedDataWithError:&error];
[urlRequest setHTTPBody:conversationData];
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/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversation *conversation = [[MSGraphConversation alloc] init];
[conversation setTopic:@"Take your wellness days and rest"];
NSMutableArray *threadsList = [[NSMutableArray alloc] init];
MSGraphConversationThread *threads = [[MSGraphConversationThread alloc] init];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Contoso cares about you: Rest and Recharge"];
[posts setBody:body];
NSMutableArray *newParticipantsList = [[NSMutableArray alloc] init];
MSGraphRecipient *newParticipants = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setName:@"Adele Vance"];
[emailAddress setAddress:@"AdeleV@contoso.onmicrosoft.com"];
[newParticipants setEmailAddress:emailAddress];
[newParticipantsList addObject: newParticipants];
[posts setNewParticipants:newParticipantsList];
[postsList addObject: posts];
[threads setPosts:postsList];
[threadsList addObject: threads];
[conversation setThreads:threadsList];
NSError *error;
NSData *conversationData = [conversation getSerializedDataWithError:&error];
[urlRequest setHTTPBody:conversationData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Conversation conversation = new Conversation();
conversation.topic = "Take your wellness days and rest";
LinkedList<ConversationThread> threadsList = new LinkedList<ConversationThread>();
ConversationThread threads = new ConversationThread();
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Contoso cares about you: Rest and Recharge";
posts.body = body;
LinkedList<Recipient> newParticipantsList = new LinkedList<Recipient>();
Recipient newParticipants = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Adele Vance";
emailAddress.address = "AdeleV@contoso.onmicrosoft.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);
threads.posts = postCollectionPage;
threadsList.add(threads);
ConversationThreadCollectionResponse conversationThreadCollectionResponse = new ConversationThreadCollectionResponse();
conversationThreadCollectionResponse.value = threadsList;
ConversationThreadCollectionPage conversationThreadCollectionPage = new ConversationThreadCollectionPage(conversationThreadCollectionResponse, null);
conversation.threads = conversationThreadCollectionPage;
graphClient.groups("29981b6a-0e57-42dc-94c9-cd24f5306196").conversations()
.buildRequest()
.post(conversation);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Conversation conversation = new Conversation();
conversation.topic = "Take your wellness days and rest";
LinkedList<ConversationThread> threadsList = new LinkedList<ConversationThread>();
ConversationThread threads = new ConversationThread();
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Contoso cares about you: Rest and Recharge";
posts.body = body;
LinkedList<Recipient> newParticipantsList = new LinkedList<Recipient>();
Recipient newParticipants = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Adele Vance";
emailAddress.address = "AdeleV@contoso.onmicrosoft.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);
threads.posts = postCollectionPage;
threadsList.add(threads);
ConversationThreadCollectionResponse conversationThreadCollectionResponse = new ConversationThreadCollectionResponse();
conversationThreadCollectionResponse.value = threadsList;
ConversationThreadCollectionPage conversationThreadCollectionPage = new ConversationThreadCollectionPage(conversationThreadCollectionResponse, null);
conversation.threads = conversationThreadCollectionPage;
graphClient.groups("29981b6a-0e57-42dc-94c9-cd24f5306196").conversations()
.buildRequest()
.post(conversation);
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewConversation()
topic := "Take your wellness days and rest"
requestBody.SetTopic(&topic)
requestBody.SetThreads( []ConversationThread {
msgraphsdk.NewConversationThread(),
SetAdditionalData(map[string]interface{}{
"posts": []Object {
}
}
}
groupId := "group-id"
result, err := graphClient.GroupsById(&groupId).Conversations().Post(requestBody)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewConversation()
topic := "Take your wellness days and rest"
requestBody.SetTopic(&topic)
requestBody.SetThreads( []ConversationThread {
msgraphsdk.NewConversationThread(),
SetAdditionalData(map[string]interface{}{
"posts": []Object {
}
}
}
groupId := "group-id"
result, err := graphClient.GroupsById(&groupId).Conversations().Post(requestBody)
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
Import-Module Microsoft.Graph.Groups
$params = @{
Topic = "Take your wellness days and rest"
Threads = @(
@{
Posts = @(
@{
Body = @{
ContentType = "html"
Content = "Contoso cares about you: Rest and Recharge"
}
NewParticipants = @(
@{
EmailAddress = @{
Name = "Adele Vance"
Address = "AdeleV@contoso.onmicrosoft.com"
}
}
)
}
)
}
)
}
New-MgGroupConversation -GroupId $groupId -BodyParameter $params
Import-Module Microsoft.Graph.Groups
$params = @{
Topic = "Take your wellness days and rest"
Threads = @(
@{
Posts = @(
@{
Body = @{
ContentType = "html"
Content = "Contoso cares about you: Rest and Recharge"
}
NewParticipants = @(
@{
EmailAddress = @{
Name = "Adele Vance"
Address = "AdeleV@contoso.onmicrosoft.com"
}
}
)
}
)
}
)
}
New-MgGroupConversation -GroupId $groupId -BodyParameter $params
Lisez la documentation du Kit de développement logiciel ( SDK ) pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider .
Réponse
Voici un exemple de réponse.
Remarque : l’objet de réponse affiché ci-après peut être raccourci pour plus de lisibilité.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('4d81ce71-486c-41e9-afc5-e41bf2d0722a')/conversations/$entity",
"id": "AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgAQADamkjVbzvRKnUq1oBRdwhk=",
"threads": [
{
"id": "AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgMkABAANqaSNVvO9EqdSrWgFF3CGRAANqaSNVvO9EqdSrWgFF3CGQ=="
}
]
}