Skip to content

Commit 05761fc

Browse files
committed
Link to chat quick start and remove the duplicated code
1 parent 6307fb5 commit 05761fc

File tree

1 file changed

+6
-118
lines changed

1 file changed

+6
-118
lines changed

articles/communication-services/quickstarts/chat/quickstart-botframework-integration.md

Lines changed: 6 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -171,114 +171,15 @@ When you have a Communication Services resource, you can set up a Communication
171171

172172
Now that you have the bot's Communication Services ID, you can create a chat thread with the bot as a participant.
173173

174-
### Create a new C# application
174+
### Follow the 'Add Chat to your app' quickstart
175175

176-
1. Run the following command to create a C# application:
176+
Follow the steps in the [Add Chat to your app](/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-csharp) quickstart to create a chat app.
177177

178-
```console
179-
dotnet new console -o ChatQuickstart
180-
```
181-
182-
1. Change your directory to the new app folder and use the `dotnet build` command to compile your application:
183-
184-
```console
185-
cd ChatQuickstart
186-
dotnet build
187-
```
188-
189-
### Install the package
190-
191-
Install the Communication Services Chat SDK for .NET:
192-
193-
```powershell
194-
dotnet add package Azure.Communication.Chat
195-
```
196-
197-
### Create a chat client
198-
199-
To create a chat client, use your Communication Services endpoint and the user access token you generated earlier. Use the `CommunicationIdentityClient` class from the Identity SDK to create a user and issue a token to pass to your chat client. Access tokens can be generated in the portal using the following [instructions](/azure/communication-services/quickstarts/identity/access-tokens).
200-
201-
Copy the following code and paste it in the *Program.cs* source file:
202-
203-
```csharp
204-
using Azure;
205-
using Azure.Communication;
206-
using Azure.Communication.Chat;
207-
using System;
208-
209-
namespace ChatQuickstart
210-
{
211-
class Program
212-
{
213-
static async System.Threading.Tasks.Task Main(string[] args)
214-
{
215-
// Your unique Communication Services endpoint
216-
Uri endpoint = new Uri("https://<RESOURCE_NAME>.communication.azure.com");
217-
218-
CommunicationTokenCredential communicationTokenCredential = new CommunicationTokenCredential(<Access_Token>);
219-
ChatClient chatClient = new ChatClient(endpoint, communicationTokenCredential);
220-
}
221-
}
222-
}
223-
```
224-
225-
### Start a chat thread with the bot
226-
227-
Use the `createChatThread` method on `chatClient` to create a chat thread. Replace the ID with the bot's Communication Services ID that you copied in this step: [Token and ACS Bot ID app](#get-a-communication-services-resource)
228-
229-
```csharp
230-
var chatParticipant = new ChatParticipant(identifier: new CommunicationUserIdentifier(id: "<BOT_ACS_ID>"))
231-
{
232-
DisplayName = "BotDisplayName"
233-
};
234-
CreateChatThreadResult createChatThreadResult = await chatClient.CreateChatThreadAsync(topic: "Hello Bot!", participants: new[] { chatParticipant });
235-
236-
```
178+
Replace the following with the values you copied in this step: [Get a Communication Service Resource](#get-a-communication-services-resource)
237179

238-
### Get a chat thread client
239-
240-
The `GetChatThreadClient` method returns a thread client for a thread.
241-
242-
```csharp
243-
ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId: createChatThreadResult.ChatThread.Id);
244-
string threadId = chatThreadClient.Id;
245-
```
246-
247-
### Send a message to a chat thread
248-
249-
To use `SendMessage` to send a message to a thread:
250-
251-
```csharp
252-
SendChatMessageOptions sendChatMessageOptions = new SendChatMessageOptions()
253-
{
254-
Content = "Hello World",
255-
MessageType = ChatMessageType.Text
256-
};
257-
258-
SendChatMessageResult sendChatMessageResult = await chatThreadClient.SendMessageAsync(sendChatMessageOptions);
259-
260-
string messageId = sendChatMessageResult.Id;
261-
```
262-
263-
### Receive chat messages from a chat thread
264-
265-
Check the list of messages for the bot's echo reply to "Hello World" by polling the `GetMessages` method on the chat thread client at set intervals:
266-
267-
```csharp
268-
AsyncPageable<ChatMessage> allMessages = chatThreadClient.GetMessagesAsync();
269-
await foreach (ChatMessage message in allMessages)
270-
{
271-
Console.WriteLine($"{message.Id}:{message.Content.Message}");
272-
}
273-
```
274-
275-
### Clean up the chat thread
276-
277-
When you're finished using the chat thread, delete the thread:
278-
279-
```csharp
280-
chatClient.DeleteChatThread(threadId);
281-
```
180+
1. Replace <Resource_Endpoint> with the Communication Services endpoint
181+
1. Replace <Access_Token> with the user access token
182+
1. Replace <Access_ID> with the bots ACS_ID
282183

283184
### Run the C# chat application locally
284185

@@ -296,19 +197,6 @@ Example output:
296197
1730405535010:Hello World
297198
```
298199

299-
300-
### Deploy the C# chat application (Optional)
301-
302-
If you have another web app service, you can deploy the chat application:
303-
304-
1. In Visual Studio, open the chat project.
305-
306-
1. Right-click the **ChatQuickstart** project and select **Publish**:
307-
308-
:::image type="content" source="./media/deploy-chat-application.png" alt-text="Screenshot that shows deploying the chat application to Azure from Visual Studio.":::
309-
310-
1. Once you publish the solution, run it and check if Echobot echoes the user message on the command prompt. Now that you have the solution you can proceed to play with the various activities that are needed for the business scenarios that you need to solve for.
311-
312200
## More things you can do with a bot
313201

314202
A bot can receive more than a plain-text message from a user in a Communications Services Chat channel. Some of the activities a bot can receive from a user include:

0 commit comments

Comments
 (0)