|
| 1 | +--- |
| 2 | +title: Get started with a click to call experience using Azure Communication Services |
| 3 | +titleSuffix: An Azure Communication Services tutorial |
| 4 | +description: Learn how to create a Calling Widget widget experience with the Azure Communication Services CallComposite to facilitate click to call. |
| 5 | +author: dmceachern |
| 6 | +manager: alkwa |
| 7 | +services: azure-communication-services |
| 8 | + |
| 9 | +ms.author: dmceachern |
| 10 | +ms.date: 06/05/2023 |
| 11 | +ms.topic: tutorial |
| 12 | +ms.service: azure-communication-services |
| 13 | +ms.subservice: calling |
| 14 | +--- |
| 15 | +# Get started with a click to call experience using Azure Communication Services |
| 16 | + |
| 17 | +[!INCLUDE [Public Preview Notice](../../includes/public-preview-include.md)] |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +This project aims to guide developers on creating a seamless click to call experience using the Azure Communication UI Library. |
| 22 | + |
| 23 | +As per your requirements, you may need to offer your customers an easy way to reach out to you without any complex setup. |
| 24 | + |
| 25 | +Click to call is a simple yet effective concept that facilitates instant interaction with, customer support, financial advisor, and other customer-facing teams. The goal of this tutorial is to assist you in making interactions with your customers just a click away. |
| 26 | + |
| 27 | +If you wish to try it out, you can download the code from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/ui-library-click-to-call). |
| 28 | + |
| 29 | +Following this tutorial will: |
| 30 | + |
| 31 | +- Allow you to control your customers audio and video experience depending on your customer scenario |
| 32 | +- Move your customers call into a new window so they can continue browsing while on the call |
| 33 | + |
| 34 | + |
| 35 | +This tutorial is broken down into three parts: |
| 36 | + |
| 37 | +- Creating your widget |
| 38 | +- using post messaging to start a calling experience in a new window |
| 39 | +- Embed your calling experience |
| 40 | + |
| 41 | +## Prerequisites |
| 42 | + |
| 43 | +- [Visual Studio Code](https://code.visualstudio.com/) on one of the [supported platforms](https://code.visualstudio.com/docs/supporting/requirements#_platforms). |
| 44 | +- [Node.js](https://nodejs.org/), Active LTS and Maintenance LTS versions (10.14.1 recommended). Use the `node --version` command to check your version. |
| 45 | + |
| 46 | + |
| 47 | +### Set up the project |
| 48 | + |
| 49 | +Only use this step if you are creating a new application. |
| 50 | + |
| 51 | +To set up the react App, we use the `create-react-app` command line tool. This tool |
| 52 | +creates an easy to run TypeScript application powered by React. This command will create a simple react application using TypeScript. |
| 53 | + |
| 54 | +```bash |
| 55 | +# Create an Azure Communication Services App powered by React. |
| 56 | +npx create-react-app ui-library-click-to-call-app --template typescript |
| 57 | + |
| 58 | +# Change to the directory of the newly created App. |
| 59 | +cd ui-library-click-to-call-app |
| 60 | +``` |
| 61 | + |
| 62 | +### Get your dependencies |
| 63 | + |
| 64 | +Then you need to update the dependency array in the `package.json` to include some beta and alpha packages from Azure Communication Services for this to work: |
| 65 | +```json |
| 66 | +"@azure/communication-calling": "1.14.1-beta.1", |
| 67 | +"@azure/communication-chat": "1.3.2-beta.2", |
| 68 | +"@azure/communication-react": "1.7.0-beta.1", |
| 69 | +"@azure/communication-calling-effects": "1.0.1", |
| 70 | +"@fluentui/react-icons": "~2.0.203", |
| 71 | +"@fluentui/react": "~8.98.3", |
| 72 | +``` |
| 73 | + |
| 74 | +Once you run these commands, you’re all set to start working on your new project. In this tutorial, we are modifying the files in the `src` directory. |
| 75 | + |
| 76 | + |
| 77 | +## Initial app setup |
| 78 | + |
| 79 | +To get started, we replace the provided `App.tsx` content with a main page that will: |
| 80 | + |
| 81 | +- Store all of the Azure Communication information that we need to create a CallAdapter to power our Calling experience |
| 82 | +- Control the different pages of our application |
| 83 | +- Register the different fluent icons we use in the UI library and some new ones for our purposes |
| 84 | + |
| 85 | +`src/App.tsx` |
| 86 | + |
| 87 | +```ts |
| 88 | +// imports needed |
| 89 | +import { CallAdapterLocator } from '@azure/communication-react'; |
| 90 | +import './App.css'; |
| 91 | +import { useEffect, useMemo, useState } from 'react'; |
| 92 | +import { CommunicationIdentifier, CommunicationUserIdentifier } from '@azure/communication-common'; |
| 93 | +import { Spinner, Stack, initializeIcons, registerIcons } from '@fluentui/react'; |
| 94 | +import { CallAdd20Regular, Dismiss20Regular } from '@fluentui/react-icons'; |
| 95 | +``` |
| 96 | + |
| 97 | +```ts |
| 98 | +type AppPages = "calling-widget" | "new-window-call"; |
| 99 | + |
| 100 | +registerIcons({ |
| 101 | + icons: { dismiss: <Dismiss20Regular />, callAdd: <CallAdd20Regular /> }, |
| 102 | +}); |
| 103 | +initializeIcons(); |
| 104 | +function App() { |
| 105 | + const [page, setPage] = useState<AppPages>("calling-widget"); |
| 106 | + |
| 107 | + /** |
| 108 | + * Token for local user. |
| 109 | + */ |
| 110 | + const token = "<Enter your Azure Communication Services token here>"; |
| 111 | + |
| 112 | + /** |
| 113 | + * User identifier for local user. |
| 114 | + */ |
| 115 | + const userId: CommunicationIdentifier = { |
| 116 | + communicationUserId: "<Enter your user Id>", |
| 117 | + }; |
| 118 | + |
| 119 | + /** |
| 120 | + * This decides where the call will be going. This supports many different calling modalities in the Call Composite. |
| 121 | + * |
| 122 | + * - Teams meeting locator: {meetingLink: 'url to join link for a meeting'} |
| 123 | + * - Azure Communication Services group call: {groupId: 'GUID that defines the call'} |
| 124 | + * - Azure Communication Services Rooms call: {roomId: 'guid that represents a rooms call'} |
| 125 | + * - Teams adhoc, Azure communications 1:n, PSTN calls all take a participants locator: {participantIds: ['Array of participant id's to call']} |
| 126 | + * |
| 127 | + * You can call teams voice apps like a Call queue with the participants locator. |
| 128 | + */ |
| 129 | + const locator: CallAdapterLocator = { |
| 130 | + participantIds: ["<Enter Participant Id's here>"], |
| 131 | + }; |
| 132 | + |
| 133 | + /** |
| 134 | + * The phone number needed from your Azure Communication Services resource to start a PSTN call. Can be created under the phone numbers. |
| 135 | + * |
| 136 | + * For more information on phone numbers and Azure Communication Services go to this link: https://learn.microsoft.com/en-us/azure/communication-services/concepts/telephony/plan-solution |
| 137 | + * |
| 138 | + * This can be left alone if not making a PSTN call. |
| 139 | + */ |
| 140 | + const alternateCallerId = "<Enter your alternate CallerId here>"; |
| 141 | + |
| 142 | + switch (page) { |
| 143 | + case "calling-widget": { |
| 144 | + return ( |
| 145 | + <Stack verticalAlign='center' style={{ height: "100%", width: "100%" }}> |
| 146 | + <Spinner |
| 147 | + label={"Getting user credentials from server"} |
| 148 | + ariaLive="assertive" |
| 149 | + labelPosition="top" |
| 150 | + /> |
| 151 | + </Stack> |
| 152 | + ); |
| 153 | + } |
| 154 | + case "new-window-call": { |
| 155 | + return ( |
| 156 | + <Stack verticalAlign='center' style={{ height: "100%", width: "100%" }}> |
| 157 | + <Spinner |
| 158 | + label={"Getting user credentials from server"} |
| 159 | + ariaLive="assertive" |
| 160 | + labelPosition="top" |
| 161 | + /> |
| 162 | + </Stack> |
| 163 | + ); |
| 164 | + } |
| 165 | + default: { |
| 166 | + return <>Something went wrong!</> |
| 167 | + } |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +export default App; |
| 172 | +``` |
| 173 | +In this snippet we register two new icons `<Dismiss20Regular/>` and `<CallAdd20Regular>`. These new icons are used inside the widget component that we are creating later. |
| 174 | + |
| 175 | +### Running the app |
| 176 | + |
| 177 | +We can then test to see that the basic application is working by running: |
| 178 | + |
| 179 | +```bash |
| 180 | +# Install the newe dependencies |
| 181 | +npm install |
| 182 | + |
| 183 | +# run the React app |
| 184 | +npm run start |
| 185 | +``` |
| 186 | + |
| 187 | +Once the app is running, you can see it on `http://localhost:3000` in your browser. You should see a little spinner saying: `getting credentials from server` as |
| 188 | +a test message. |
| 189 | + |
| 190 | +## Next steps |
| 191 | + |
| 192 | +> [!div class="nextstepaction"] |
| 193 | +> [Part 1: Creating your widget](./calling-widget-tutorial-part-1-creating-your-widget.md) |
0 commit comments