Skip to content

Commit

Permalink
Chat Samples v2 Migration (#15317)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuChen-Microsoft authored May 26, 2021
1 parent 49b2f90 commit 371af9d
Show file tree
Hide file tree
Showing 25 changed files with 503 additions and 263 deletions.
20 changes: 14 additions & 6 deletions sdk/communication/communication-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
"build:autorest": "autorest ./swagger/README.md --typescript --version=3.0.6267 --v3 --package-version=1.1.0-beta.1 && rushx format",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "dev-tool samples prep && cd dist-samples && tsc -p .",
"build:samples": "echo Obsolete.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-* temp types *.tgz *.log",
"execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples",
"execute:js-samples": "dev-tool samples run dist-samples/javascript",
"execute:ts-samples": "dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/",
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "karma start --single-run",
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000 dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
Expand Down Expand Up @@ -125,5 +123,15 @@
"typescript": "~4.2.0",
"util": "^0.12.1",
"typedoc": "0.15.2"
},
"//sampleConfiguration": {
"productName": "Azure Communication Services - Chat",
"productSlugs": [
"azure",
"azure-communication-services"
],
"requiredResources": {
"Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource"
}
}
}
9 changes: 3 additions & 6 deletions sdk/communication/communication-chat/sample.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Used in most samples. Retrieve these values from a Communication Services instance
# Used in most samples. Retrieve these values from a Communication Services resource
# in the Azure Portal.
COMMUNICATION_CONNECTION_STRING=""

# Our tests assume that TEST_MODE is "playback" by default. You can
# change it to "record" to generate new recordings, or "live" to bypass the recorder entirely.
# TEST_MODE=record
COMMUNICATION_CONNECTION_STRING="endpoint=https://<resource name>.communication.azure.net/;accessKey=<key>"
COMMUNICATION_ENDPOINT="https://<resource name>.communication.azure.com"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

/**
* Demonstrates how to use the ChatThreadClient to do message operations
* @summary Perform message thread operations using the ChatThreadClient.
*/

import { ChatClient } from "@azure/communication-chat";
Expand Down Expand Up @@ -58,8 +58,7 @@ export async function main() {
console.log("Deleted message.");
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
main().catch((error) => {
console.error("Encountered an error in message operations: ", error);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

/**
* Demonstrates how to use the ChatThreadClient to do participant operations
* @summary Demonstrates how to use the ChatThreadClient to do participant operations.
*/

import { ChatClient } from "@azure/communication-chat";
Expand Down Expand Up @@ -73,8 +73,7 @@ export async function main() {
console.log("Removed chat participant user.");
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
main().catch((error) => {
console.error("Encountered an error in participants operations: ", error);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

/**
* Demonstrates how to use the ChatClient to do thread operations
* @summary Perform thread operations using the ChatClient.
*/

import { ChatClient } from "@azure/communication-chat";
Expand Down Expand Up @@ -68,8 +68,7 @@ export async function main() {
await chatClient.deleteChatThread(threadId);
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
main().catch((error) => {
console.error("Encountered an error in thread operations: ", error);
process.exit(1);
});
62 changes: 0 additions & 62 deletions sdk/communication/communication-chat/samples/javascript/README.md

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions sdk/communication/communication-chat/samples/tsconfig.json

This file was deleted.

68 changes: 0 additions & 68 deletions sdk/communication/communication-chat/samples/typescript/README.md

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
page_type: sample
languages:
- javascript
products:
- azure
- azure-communication-services
urlFragment: communication-chat-javascript
---

# Azure Communication Services - Chat client library samples for JavaScript

These sample programs show how to use the JavaScript client libraries for Azure Communication Services - Chat in some common scenarios.

| **File Name** | **Description** |
| --------------------------------------------------- | -------------------------------------------------------------------------- |
| [messageOperations.js][messageoperations] | Perform message thread operations using the ChatThreadClient. |
| [participantsOperations.js][participantsoperations] | Demonstrates how to use the ChatThreadClient to do participant operations. |
| [threadOperations.js][threadoperations] | Perform thread operations using the ChatClient. |

## Prerequisites

The sample programs are compatible with Node.js >=12.0.0.

You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs:

- [Azure Communication Services account][createinstance_azurecommunicationservicesaccount]

Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.

Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].

## Setup

To run the samples using the published version of the package:

1. Install the dependencies using `npm`:

```bash
npm install
```

2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.

3. Run whichever samples you like (note that some samples may require additional setup, see the table above):

```bash
node messageOperations.js
```

Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx cross-env COMMUNICATION_CONNECTION_STRING="<communication connection string>" node messageOperations.js
```

## Next Steps

Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.

[messageoperations]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/communication/communication-chat/samples/v1/javascript/messageOperations.js
[participantsoperations]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/communication/communication-chat/samples/v1/javascript/participantsOperations.js
[threadoperations]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/communication/communication-chat/samples/v1/javascript/threadOperations.js
[apiref]: https://docs.microsoft.com/javascript/api/@azure/communication-chat
[freesub]: https://azure.microsoft.com/free/
[createinstance_azurecommunicationservicesaccount]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource
[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/communication/communication-chat/README.md
Loading

0 comments on commit 371af9d

Please sign in to comment.