├── .github
├── CODE_OF_CONDUCT.md
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── CallAutomation-Connect-Room
├── README.md
├── data
│ ├── callingRoomQuickstart.png
│ ├── connectCall.png
│ ├── createRoom.png
│ ├── joinRoomCall.png
│ ├── roomId.png
│ └── tokens.png
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── communication
│ │ └── callautomation
│ │ ├── AppConfig.java
│ │ ├── Main.java
│ │ ├── ProgramSample.java
│ │ └── config
│ │ └── WebConfig.java
│ └── resources
│ ├── application.yml
│ └── templates
│ └── index.html
├── CallAutomation_Live_Transcription
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── communication
│ │ └── callautomation
│ │ ├── AppConfig.java
│ │ ├── Main.java
│ │ ├── ProgramSample.java
│ │ ├── WebSocketConfig.java
│ │ └── WebSocketHandler.java
│ └── resources
│ └── application.yml
├── CallAutomation_OpenAI_Sample
├── README.md
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── communication
│ │ │ └── callautomation
│ │ │ ├── AppConfig.java
│ │ │ ├── Main.java
│ │ │ └── ProgramSample.java
│ │ └── resources
│ │ └── application.yml
└── static
│ ├── Confirmed.wav
│ ├── Goodbye.wav
│ ├── Invalid.wav
│ ├── MainMenu.wav
│ ├── OutboundCallDesign.png
│ └── Timeout.wav
├── CallAutomation_OutboundCalling
├── README.md
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── communication
│ │ │ └── callautomation
│ │ │ ├── AppConfig.java
│ │ │ ├── Main.java
│ │ │ └── ProgramSample.java
│ │ └── resources
│ │ └── application.yml
└── static
│ └── OutboundCallDesign.png
├── CallRecording
├── README.MD
├── Recordings API.postman_collection.json
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── communication
│ │ └── callrecording
│ │ ├── ApiApplication.java
│ │ ├── ConfigurationManager.java
│ │ └── Controller
│ │ └── RecordingsController.java
│ └── resources
│ └── config.properties
├── DirectRouting
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
├── LICENSE.md
├── LookupNumber
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── lookup
│ └── quickstart
│ └── App.java
├── ManageTeamsIdentityMobileAndDesktop
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
├── OutboundCallReminder
├── pom.xml
├── readme.md
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── outboundcallreminder
│ ├── App.java
│ ├── CallConfiguration.java
│ ├── CommunicationIdentifierKind.java
│ ├── ConfigurationManager.java
│ ├── Controllers
│ └── OutboundCallController.java
│ ├── EventHandler
│ ├── EventAuthHandler.java
│ ├── EventDispatcher.java
│ └── NotificationCallback.java
│ ├── Logger.java
│ ├── Ngrok
│ ├── NgrokConnector.java
│ └── NgrokService.java
│ ├── OutboundCallReminder.java
│ ├── audio
│ ├── custom-message.wav
│ └── sample-message.wav
│ └── config.properties
├── PhoneNumbers
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
├── README.md
├── ServerRecording
├── .gitignore
├── README.MD
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── acsrecording
│ │ │ └── api
│ │ │ ├── ApiApplication.java
│ │ │ ├── ConfigurationManager.java
│ │ │ ├── Controller
│ │ │ └── CallRecordingController.java
│ │ │ └── Models
│ │ │ ├── AudioConfiguration.java
│ │ │ ├── FileDownloadType.java
│ │ │ ├── FileFormat.java
│ │ │ ├── Mapper.java
│ │ │ ├── RecordingInfo.java
│ │ │ ├── Root.java
│ │ │ └── VideoConfiguration.java
│ └── resources
│ │ ├── application.properties
│ │ └── config.properties
│ └── test
│ └── java
│ └── com
│ └── acsrecording
│ └── api
│ └── ApiApplicationTests.java
├── access-token-quickstart
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
├── chat-quickstart-java
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
├── jobrouter-quickstart-java
├── pom.xml
├── readme.md
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── communication
│ │ └── jobrouter
│ │ └── quickstart
│ │ └── App.java
│ └── test
│ └── java
│ └── com
│ └── communication
│ └── jobrouter
│ └── quickstart
│ └── AppTest.java
├── rooms-quickstart-java
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── rooms
│ └── quickstart
│ └── App.java
├── send-email-advanced
├── README.md
├── send-email-attachments
│ ├── attachment.pdf
│ ├── attachment.txt
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── communication
│ │ └── email
│ │ └── App.java
├── send-email-inline-attachments
│ ├── inline-attachment.jpg
│ ├── inline-attachment.png
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── communication
│ │ └── email
│ │ └── App.java
└── send-email-multiple-recipients
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── email
│ └── App.java
├── send-email
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── email
│ └── App.java
├── send-sms-quickstart
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── communication
│ └── quickstart
│ └── App.java
└── use-managed-Identity
├── README.md
├── pom.xml
└── src
└── main
└── java
└── com
└── communication
└── quickstart
└── App.java
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [project-title] Changelog
2 |
3 |
4 | # x.y.z (yyyy-mm-dd)
5 |
6 | *Features*
7 | * ...
8 |
9 | *Bug Fixes*
10 | * ...
11 |
12 | *Breaking Changes*
13 | * ...
14 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to [project-title]
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
6 |
7 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/README.md:
--------------------------------------------------------------------------------
1 | |page_type| languages |products
2 | |---|---------------------------------------|---|
3 | |sample|
Java
|
azure
azure-communication-services
|
4 |
5 | # Connect to a room call using Call Automation SDK
6 |
7 | In this quickstart sample, we cover how you can use Call Automation SDK to connect to an active Azure Communication Services (ACS) Rooms call with a connect endpoint.
8 | This involves creating a room call with room id and users and enabling PSTN dial out to add PSTN participant(s).
9 |
10 | ## Prerequisites
11 |
12 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
13 | - A deployed Communication Services resource. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource).
14 | - A [phone number](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/telephony/get-phone-number) in your Azure Communication Services resource that can make outbound calls. NB: phone numbers are not available in free subscriptions.
15 | - Create Azure AI Multi Service resource. For details, see [Create an Azure AI Multi service](https://learn.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account).
16 | - [Java Development Kit (JDK) Microsoft.OpenJDK.17](https://learn.microsoft.com/en-us/java/openjdk/download)
17 | - [Apache Maven](https://maven.apache.org/download.cgi)
18 | - Create and host a Azure Dev Tunnel. Instructions [here](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started)
19 | - To know about rooms see https://learn.microsoft.com/en-us/azure/communication-services/concepts/rooms/room-concept
20 | - To join room call see https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/rooms/join-rooms-call?pivots=platform-web
21 |
22 | ## Before running the sample for the first time
23 |
24 | 1. Open an instance of PowerShell, Windows Terminal, Command Prompt or equivalent and navigate to the directory that you would like to clone the sample to.
25 | 2. git clone `https://github.com/Azure-Samples/communication-services-java-quickstarts.git`.
26 | 3. cd into the `CallAutomation-Connect-Room` folder.
27 | 4. From the root of the above folder, and with node installed, run `mvn clean package`
28 |
29 | ## Before running calling rooms quickstart
30 | 1. To initiate rooms call with room id https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/calling-rooms-quickstart
31 | 2. cd into the `calling-rooms-quickstart` folder.
32 | 3. From the root of the above folder, and with node installed, run `npm install`
33 | 4. to run sample `npx webpack serve --config webpack.config.js`
34 |
35 | ### Setup and host your Azure DevTunnel
36 |
37 | [Azure DevTunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) is an Azure service that enables you to share local web services hosted on the internet. Use the commands below to connect your local development environment to the public internet. This creates a tunnel with a persistent endpoint URL and which allows anonymous access. We will then use this endpoint to notify your application of calling events from the ACS Call Automation service.
38 |
39 | ```bash
40 | devtunnel create --allow-anonymous
41 | devtunnel port create -p 8080
42 | devtunnel host
43 | ```
44 |
45 | ### Configuring application
46 |
47 | - Open the application.yml file in the resources folder to configure the following settings
48 |
49 | - `connectionstring`: Azure Communication Service resource's connection string.
50 | - `callerphonenumber`: Phone number associated with the Azure Communication Service resource.
51 | - `targetphonenumber`: Target Phone number.
52 |
53 | Format: "OutboundTarget(Phone Number)".
54 |
55 | For e.g. "+1425XXXAAAA"
56 | - `basecallbackuri`: Base url of the app. For local development use dev tunnel url.
57 | - `cognitiveServiceEndpoint` Cognitive service endpoint.
58 |
59 | ### Run the application
60 |
61 | - Navigate to the directory containing the pom.xml file and use the following mvn commands:
62 | - Compile the application: mvn compile
63 | - Build the package: mvn package
64 | - Execute the app: mvn exec:java
65 | - Access the UI at http://localhost:8080/
66 |
67 | ### Creating and connecting to room call.
68 |
69 | 1. Navigate to `http://localhost:8080/` or devtunnel url to create users and room id 
70 | 2. Open two tabs for Presenter and attendee 
71 | 3. Copy tokens for presenter and attendee from 
72 | 4. Initialize call agent with tokens for both presenter and attendee.
73 | 5. Take room id  and initiate rooms call for both users. 
74 | 6. Connect room call with call automation connect call endpoint. 
75 |
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/callingRoomQuickstart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/callingRoomQuickstart.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/connectCall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/connectCall.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/createRoom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/createRoom.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/joinRoomCall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/joinRoomCall.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/roomId.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/roomId.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/data/tokens.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation-Connect-Room/data/tokens.png
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/src/main/java/com/communication/callautomation/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import lombok.Getter;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.bind.ConstructorBinding;
6 |
7 | @ConfigurationProperties(prefix = "acs")
8 | @Getter
9 | public class AppConfig {
10 | private final String connectionString;
11 | private final String basecallbackuri;
12 | private final String callerphonenumber;
13 | private final String targetphonenumber;
14 | private final String cognitiveServiceEndpoint;
15 |
16 | @ConstructorBinding
17 | AppConfig(final String connectionString,
18 | final String basecallbackuri,
19 | final String callerphonenumber,
20 | final String targetphonenumber,
21 | final String cognitiveServiceEndpoint,
22 | final String targetTeamsUserId,
23 | final String[] allowedOrigins) {
24 | this.connectionString = connectionString;
25 | this.basecallbackuri = basecallbackuri;
26 | this.callerphonenumber = callerphonenumber;
27 | this.targetphonenumber = targetphonenumber;
28 | this.cognitiveServiceEndpoint = cognitiveServiceEndpoint;
29 | }
30 |
31 | public String getCallBackUri() {
32 | return basecallbackuri + "/api/callback";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/src/main/java/com/communication/callautomation/Main.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 |
7 | @SpringBootApplication
8 | @EnableConfigurationProperties(value = AppConfig.class)
9 | public class Main {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Main.class, args);
12 | }
13 | }
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/src/main/java/com/communication/callautomation/config/WebConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation.config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7 |
8 | import com.communication.callautomation.AppConfig;
9 |
10 | @Configuration
11 | public class WebConfig implements WebMvcConfigurer {
12 |
13 | @Autowired
14 | private AppConfig appConfig; // Inject AppConfig to access allowedOrigins
15 |
16 | @Override
17 | public void addCorsMappings(CorsRegistry registry) {
18 | // Allow all APIs to accept CORS requests from your frontend
19 | registry.addMapping("/**") // Apply to all endpoints
20 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // Allowed HTTP methods
21 | .allowedHeaders("*") // Allow all headers
22 | .maxAge(3600); // Cache the pre-flight response for 1 hour
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: CallAutomation-Connect-Room
4 |
5 | server:
6 | port: 8080
7 |
8 | acs:
9 | connectionstring:
10 | basecallbackuri:
11 | callerphonenumber:
12 | targetphonenumber:
13 | cognitiveServiceEndpoint:
14 |
--------------------------------------------------------------------------------
/CallAutomation-Connect-Room/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Azure Communication Services Quickstart
6 |
7 |
8 |
9 |
|
4 |
5 | # Call Live Transcription - Quick Start Sample
6 |
7 | This sample application shows how the Azure Communication Services - Call Automation SDK can be used generate the live transcription between PSTN calls.
8 | It accepts an incoming call from a phone number, performs DTMF recognition, and transfer the call to agent. You can see the live transcription in websocket during the conversation between agent and user
9 | This sample application is also capable of making multiple concurrent inbound calls. The application is a web-based application built on Java's Spring framework.
10 |
11 |
12 | ## Prerequisites
13 |
14 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
15 | - A deployed Communication Services resource. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource).
16 | - A [phone number](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/telephony/get-phone-number) in your Azure Communication Services resource that can make outbound calls. NB: phone numbers are not available in free subscriptions.
17 | - [Java Development Kit (JDK) Microsoft.OpenJDK.17](https://learn.microsoft.com/en-us/java/openjdk/download)
18 | - [Apache Maven](https://maven.apache.org/download.cgi)
19 | - Create Azure AI Multi Service resource. For details, see [Create an Azure AI Multi service](https://learn.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account).
20 |
21 | ## Before running the sample for the first time
22 |
23 | ### Setup and host your Azure DevTunnel
24 |
25 | [Azure DevTunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) is an Azure service that enables you to share local web services hosted on the internet. Use the commands below to connect your local development environment to the public internet. This creates a tunnel with a persistent endpoint URL and which allows anonymous access. We will then use this endpoint to notify your application of calling events from the ACS Call Automation service.
26 |
27 | ```bash
28 | devtunnel create --allow-anonymous
29 | devtunnel port create -p 8080
30 | devtunnel host
31 | ```
32 |
33 | ### Configuring application
34 |
35 | - Open the application.yml file in the resources folder to configure the following settings
36 |
37 | - `connectionstring`: Azure Communication Service resource's connection string.
38 | - `basecallbackuri`: Base url of the app. For local development use dev tunnel url.
39 | - `cognitiveServicesUrl`: The Cognitive Services endpoint
40 | - `acsPhoneNumber`: Acs Phone Number
41 | - `agentPhoneNumber`: Agent Phone Number
42 | - `locale`: Transcription locale
43 |
44 | ### Run the application
45 |
46 | - Open new terminal and navigate to the directory containing the pom.xml file and use the following mvn commands to run app:
47 | - Compile the application: mvn compile
48 | - Build the package: mvn package
49 | - Execute the app: `mvn exec:java -Papp`
50 | - Access the Swagger UI at http://localhost:8080/swagger-ui/index.html
51 | - Register an EventGrid Webhook for the IncomingCall Event that points to your DevTunnel URI endpoint ex `{basecallbackuri}/api/incomingCall` and register Recording File Status Updated event to you recordingstatus api endpoint ex. `{basecallbackuri}/api/recordingFileStatus`. Instructions [here](https://learn.microsoft.com/en-us/azure/communication-services/concepts/call-automation/incoming-call-notification).
52 |
53 | Once that's completed you should have a running application. The best way to test this is to place a call to your ACS phone number and talk to your intelligent agent.
--------------------------------------------------------------------------------
/CallAutomation_Live_Transcription/src/main/java/com/communication/callautomation/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import lombok.Getter;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.bind.ConstructorBinding;
6 |
7 | @ConfigurationProperties(prefix = "acs")
8 | @Getter
9 | public class AppConfig {
10 | private final String connectionString;
11 | private final String basecallbackuri;
12 | private final String cognitiveServicesUrl;
13 | private final String agentPhoneNumber;
14 | private final String acsPhoneNumber;
15 | private final String locale;
16 |
17 | @ConstructorBinding
18 | AppConfig(final String connectionString,
19 | final String basecallbackuri,
20 | final String cognitiveServicesUrl,
21 | final String agentPhoneNumber,
22 | final String acsPhoneNumber,
23 | final String locale) {
24 | this.connectionString = connectionString;
25 | this.basecallbackuri = basecallbackuri;
26 | this.cognitiveServicesUrl = cognitiveServicesUrl;
27 | this.agentPhoneNumber = agentPhoneNumber;
28 | this.acsPhoneNumber = acsPhoneNumber;
29 | this.locale = locale;
30 | }
31 |
32 | public String getCallBackUri() {
33 | return basecallbackuri + "/api/callback";
34 | }
35 |
36 | public String getCallBackUriForRecordingApis() {
37 | return basecallbackuri + "/api/recordingcallback";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/CallAutomation_Live_Transcription/src/main/java/com/communication/callautomation/Main.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 |
7 | @SpringBootApplication
8 | @EnableConfigurationProperties(value = AppConfig.class)
9 | public class Main {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Main.class, args);
12 | }
13 | }
--------------------------------------------------------------------------------
/CallAutomation_Live_Transcription/src/main/java/com/communication/callautomation/WebSocketConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.socket.config.annotation.EnableWebSocket;
5 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
6 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
7 |
8 | @Configuration
9 | @EnableWebSocket // Enables WebSocket support
10 | public class WebSocketConfig implements WebSocketConfigurer {
11 |
12 | @Override
13 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
14 | registry.addHandler(new WebSocketHandler(), "/ws") // Registering WebSocket handler
15 | .setAllowedOrigins("*"); // Allow connections from any origin (adjust as needed)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CallAutomation_Live_Transcription/src/main/java/com/communication/callautomation/WebSocketHandler.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.web.socket.WebSocketSession;
4 | import org.springframework.web.socket.handler.TextWebSocketHandler;
5 | import org.springframework.web.socket.TextMessage;
6 | import com.azure.communication.callautomation.StreamingDataParser;
7 | import com.azure.communication.callautomation.models.StreamingData;
8 | import com.azure.communication.callautomation.models.TranscriptionData;
9 | import com.azure.communication.callautomation.models.TranscriptionMetadata;
10 | import com.azure.communication.callautomation.models.WordData;
11 |
12 | public class WebSocketHandler extends TextWebSocketHandler {
13 |
14 | @Override
15 | protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
16 | String payload = message.getPayload();
17 | System.out.println("Received message: " + payload);
18 |
19 | // Parse the message into StreamingData (custom data parsing logic)
20 | StreamingData data = StreamingDataParser.parse(payload);
21 |
22 | // Handle TranscriptionMetadata
23 | if (data instanceof TranscriptionMetadata) {
24 | TranscriptionMetadata transcriptionMetadata = (TranscriptionMetadata) data;
25 | System.out.println("----------------------------------------------------------------");
26 | System.out.println("TRANSCRIPTION SUBSCRIPTION ID:-->" + transcriptionMetadata.getTranscriptionSubscriptionId());
27 | System.out.println("LOCALE:-->" + transcriptionMetadata.getLocale());
28 | System.out.println("CALL CONNECTION ID:-->" + transcriptionMetadata.getCallConnectionId());
29 | System.out.println("CORRELATION ID:-->" + transcriptionMetadata.getCorrelationId());
30 | System.out.println("----------------------------------------------------------------");
31 | }
32 |
33 | // Handle TranscriptionData
34 | if (data instanceof TranscriptionData) {
35 | TranscriptionData transcriptionData = (TranscriptionData) data;
36 | System.out.println("----------------------------------------------------------------");
37 | System.out.println("TEXT:-->" + transcriptionData.getText());
38 | System.out.println("FORMAT:-->" + transcriptionData.getFormat());
39 | System.out.println("CONFIDENCE:-->" + transcriptionData.getConfidence());
40 | System.out.println("OFFSET:-->" + transcriptionData.getOffset());
41 | System.out.println("DURATION:-->" + transcriptionData.getDuration());
42 |
43 | String participant = transcriptionData.getParticipant().getRawId() != null
44 | ? transcriptionData.getParticipant().getRawId()
45 | : "";
46 | System.out.println("PARTICIPANT:-->" + participant);
47 | System.out.println("RESULT STATUS:-->" + transcriptionData.getResultStatus());
48 |
49 | // Print word data (example of transcribed words)
50 | for (WordData word : transcriptionData.getTranscripeWords()) {
51 | System.out.println("TEXT:-->" + word.getText());
52 | System.out.println("OFFSET:-->" + word.getOffset());
53 | System.out.println("DURATION:-->" + word.getDuration());
54 | }
55 | System.out.println("----------------------------------------------------------------");
56 | }
57 |
58 | // Send an echo response back to the client
59 | session.sendMessage(new TextMessage("Echo: " + payload));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/CallAutomation_Live_Transcription/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: CallAutomation_LiveTranscription
4 |
5 | server:
6 | port: 8080
7 |
8 | acs:
9 | connectionstring:
10 | basecallbackuri:
11 | cognitiveServicesUrl:
12 | acsPhoneNumber:
13 | agentPhoneNumber:
14 | locale:
15 |
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/README.md:
--------------------------------------------------------------------------------
1 | |page_type| languages |products
2 | |---|---------------------------------------|---|
3 | |sample|
Java
|
azure
azure-communication-services
|
4 |
5 | # Call Automation - Quick Start Sample
6 |
7 | This sample application shows how the Azure Communication Services - Call Automation SDK can be used with Azure OpenAI Service to enable intelligent conversational agents.
8 | It answers an inbound call, does a speech recognition with the recognize API and Cognitive Services, uses OpenAi Services with the input speech and responds to the caller through Cognitive Services' Text to Speech.
9 | This sample application configured for accepting input speech until the caller terminates the call or a long silence is detected.
10 | This sample application is also capable of making multiple concurrent inbound calls. The application is a web-based application built on Java's Spring framework.
11 |
12 |
13 | ## Prerequisites
14 |
15 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
16 | - A deployed Communication Services resource. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource).
17 | - A [phone number](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/telephony/get-phone-number) in your Azure Communication Services resource that can make outbound calls. NB: phone numbers are not available in free subscriptions.
18 | - [Java Development Kit (JDK) Microsoft.OpenJDK.17](https://learn.microsoft.com/en-us/java/openjdk/download)
19 | - [Apache Maven](https://maven.apache.org/download.cgi)
20 | - Create and host a Azure Dev Tunnel. Instructions [here](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started)
21 | - Create an Azure Cognitive Services resource. For details, see Create an Azure Cognitive Services Resource.
22 | - An Azure OpenAI Resource and Deployed Model. See https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal.
23 |
24 | ## Before running the sample for the first time
25 |
26 | - Open the application.yml file in the resources folder to configure the following settings
27 |
28 | - `connectionstring`: Azure Communication Service resource's connection string.
29 | - `basecallbackuri`: Base url of the app. For local development use dev tunnel url.
30 | - `cognitiveServicesUrl`: The Cognitive Services endpoint
31 | - `azureOpenAiServiceKey`: Open AI's Service Key
32 | - `azureOpenAiServiceEndpoint`: Open AI's Service Endpoint
33 | - `openAiModelName`: Open AI's Model name
34 | - `agentPhoneNumber`: Agent Phone Number
35 |
36 |
37 | ### Setup and host your Azure DevTunnel
38 |
39 | [Azure DevTunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/overview) is an Azure service that enables you to share local web services hosted on the internet. Use the commands below to connect your local development environment to the public internet. This creates a tunnel with a persistent endpoint URL and which allows anonymous access. We will then use this endpoint to notify your application of calling events from the ACS Call Automation service.
40 |
41 | ```bash
42 | devtunnel create --allow-anonymous
43 | devtunnel port create -p 8080
44 | devtunnel host
45 | ```
46 |
47 | ### Run the application
48 |
49 | - Navigate to the directory containing the pom.xml file and use the following mvn commands:
50 | - Compile the application: mvn compile
51 | - Build the package: mvn package
52 | - Execute the app: mvn exec:java
53 | - Access the Swagger UI at http://localhost:8080/swagger-ui.html
54 | - Try the GET /outboundCall to run the Sample Application
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/src/main/java/com/communication/callautomation/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import lombok.Getter;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.bind.ConstructorBinding;
6 |
7 | @ConfigurationProperties(prefix = "acs")
8 | @Getter
9 | public class AppConfig {
10 | private final String connectionString;
11 | private final String basecallbackuri;
12 | private final String cognitiveServicesUrl;
13 | private final String azureOpenAiServiceKey;
14 | private final String azureOpenAiServiceEndpoint;
15 | private final String openAiModelName;
16 | private final String agentPhoneNumber;
17 |
18 | @ConstructorBinding
19 | AppConfig(final String connectionString,
20 | final String basecallbackuri,
21 | final String cognitiveServicesUrl,
22 | final String azureOpenAiServiceKey,
23 | final String azureOpenAiServiceEndpoint,
24 | final String openAiModelName,
25 | final String agentPhoneNumber) {
26 | this.connectionString = connectionString;
27 | this.basecallbackuri = basecallbackuri;
28 | this.cognitiveServicesUrl = cognitiveServicesUrl;
29 | this.azureOpenAiServiceKey = azureOpenAiServiceKey;
30 | this.azureOpenAiServiceEndpoint = azureOpenAiServiceEndpoint;
31 | this.openAiModelName = openAiModelName;
32 | this.agentPhoneNumber = agentPhoneNumber;
33 | }
34 |
35 | public String getCallBackUri() {
36 | return basecallbackuri + "/api/callback";
37 | }
38 |
39 | public String getCallBackUriForRecordingApis() {
40 | return basecallbackuri + "/api/recordingcallback";
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/src/main/java/com/communication/callautomation/Main.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 |
7 | @SpringBootApplication
8 | @EnableConfigurationProperties(value = AppConfig.class)
9 | public class Main {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Main.class, args);
12 | }
13 | }
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: CallAutomation_OutboundCalling
4 |
5 | server:
6 | port: 8080
7 |
8 | acs:
9 | connectionstring:
10 | basecallbackuri:
11 | cognitiveServicesUrl:
12 | azureOpenAiServiceKey:
13 | azureOpenAiServiceEndpoint:
14 | openAiModelName:
15 | agentPhoneNumber:
16 |
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/Confirmed.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/Confirmed.wav
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/Goodbye.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/Goodbye.wav
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/Invalid.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/Invalid.wav
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/MainMenu.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/MainMenu.wav
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/OutboundCallDesign.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/OutboundCallDesign.png
--------------------------------------------------------------------------------
/CallAutomation_OpenAI_Sample/static/Timeout.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OpenAI_Sample/static/Timeout.wav
--------------------------------------------------------------------------------
/CallAutomation_OutboundCalling/README.md:
--------------------------------------------------------------------------------
1 | |page_type| languages |products
2 | |---|---------------------------------------|---|
3 | |sample|
Java
|
azure
azure-communication-services
|
4 |
5 | # Call Automation - Quick Start Sample
6 |
7 | In this quickstart, we cover how you can use Call Automation SDK to make an outbound call to a phone number and use the newly announced integration with Azure AI services to play dynamic prompts to participants using Text-to-Speech and recognize user voice input through Speech-to-Text to drive business logic in your application.
8 |
9 | # Design
10 |
11 | 
12 |
13 | ## Prerequisites
14 |
15 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
16 | - A deployed Communication Services resource. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource).
17 | - A [phone number](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/telephony/get-phone-number) in your Azure Communication Services resource that can make outbound calls. NB: phone numbers are not available in free subscriptions.
18 | - Create Azure AI Multi Service resource. For details, see [Create an Azure AI Multi service](https://learn.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account).
19 | - [Java Development Kit (JDK) Microsoft.OpenJDK.17](https://learn.microsoft.com/en-us/java/openjdk/download)
20 | - [Apache Maven](https://maven.apache.org/download.cgi)
21 | - Create and host a Azure Dev Tunnel. Instructions [here](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started)
22 | - (Optional) A Microsoft Teams user with a phone license that is `voice` enabled. Teams phone license is required to add Teams users to the call. Learn more about Teams licenses [here](https://www.microsoft.com/microsoft-teams/compare-microsoft-teams-bundle-options). Learn about enabling phone system with `voice` [here](https://learn.microsoft.com/microsoftteams/setting-up-your-phone-system). You also need to complete the prerequisite step [Authorization for your Azure Communication Services Resource](https://learn.microsoft.com/azure/communication-services/how-tos/call-automation/teams-interop-call-automation?pivots=programming-language-javascript#step-1-authorization-for-your-azure-communication-services-resource-to-enable-calling-to-microsoft-teams-users) to enable calling to Microsoft Teams users.
23 |
24 | ## Before running the sample for the first time
25 |
26 | - Open the application.yml file in the resources folder to configure the following settings
27 |
28 | - `connectionstring`: Azure Communication Service resource's connection string.
29 | - `callerphonenumber`: Phone number associated with the Azure Communication Service resource.
30 | - `targetphonenumber`: Target Phone number.
31 |
32 | Format: "OutboundTarget(Phone Number)".
33 |
34 | For e.g. "+1425XXXAAAA"
35 | - `basecallbackuri`: Base url of the app. For local development use dev tunnel url.
36 | - `cognitiveServiceEndpoint`: Cognitive Service Endpoint.
37 | - `targetTeamsUserId`: (Optional) update field with the Microsoft Teams user Id you would like to add to the call. See [Use Graph API to get Teams user Id](../../../how-tos/call-automation/teams-interop-call-automation.md#step-2-use-the-graph-api-to-get-microsoft-entra-object-id-for-teams-users-and-optionally-check-their-presence). Uncomment the below snippet in ProgramSample.java to enable Teams Interop scenario.
38 | ```
39 | client.getCallConnection(callConnectionId).addParticipant(
40 | new CallInvite(new MicrosoftTeamsUserIdentifier(appConfig.getTargetTeamsUserId()))
41 | .setSourceDisplayName("Jack (Contoso Tech Support)"));
42 | ```
43 |
44 | ### Setup and host your Azure DevTunnel
45 |
46 | [Azure DevTunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/overview) is an Azure service that enables you to share local web services hosted on the internet. Use the commands below to connect your local development environment to the public internet. This creates a tunnel with a persistent endpoint URL and which allows anonymous access. We will then use this endpoint to notify your application of calling events from the ACS Call Automation service.
47 |
48 | ```bash
49 | devtunnel create --allow-anonymous
50 | devtunnel port create -p 8080
51 | devtunnel host
52 | ```
53 |
54 | ### Run the application
55 |
56 | - Navigate to the directory containing the pom.xml file and use the following mvn commands:
57 | - Compile the application: mvn compile
58 | - Build the package: mvn package
59 | - Execute the app: mvn exec:java
60 | - Access the Swagger UI at http://localhost:8080/swagger-ui.html
61 | - Try the GET /outboundCall to run the Sample Application
62 |
--------------------------------------------------------------------------------
/CallAutomation_OutboundCalling/src/main/java/com/communication/callautomation/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import lombok.Getter;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.bind.ConstructorBinding;
6 |
7 | @ConfigurationProperties(prefix = "acs")
8 | @Getter
9 | public class AppConfig {
10 | private final String connectionString;
11 | private final String basecallbackuri;
12 | private final String callerphonenumber;
13 | private final String targetphonenumber;
14 | private final String cognitiveServiceEndpoint;
15 | private final String targetTeamsUserId;
16 |
17 | @ConstructorBinding
18 | AppConfig(final String connectionString,
19 | final String basecallbackuri,
20 | final String callerphonenumber,
21 | final String targetphonenumber,
22 | final String cognitiveServiceEndpoint,
23 | final String targetTeamsUserId) {
24 | this.connectionString = connectionString;
25 | this.basecallbackuri = basecallbackuri;
26 | this.callerphonenumber = callerphonenumber;
27 | this.targetphonenumber = targetphonenumber;
28 | this.cognitiveServiceEndpoint = cognitiveServiceEndpoint;
29 | this.targetTeamsUserId = targetTeamsUserId;
30 | }
31 |
32 | public String getCallBackUri() {
33 | return basecallbackuri + "/api/callback";
34 | }
35 |
36 | public String getCallBackUriForRecordingApis() {
37 | return basecallbackuri + "/api/recordingcallback";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/CallAutomation_OutboundCalling/src/main/java/com/communication/callautomation/Main.java:
--------------------------------------------------------------------------------
1 | package com.communication.callautomation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 |
7 | @SpringBootApplication
8 | @EnableConfigurationProperties(value = AppConfig.class)
9 | public class Main {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Main.class, args);
12 | }
13 | }
--------------------------------------------------------------------------------
/CallAutomation_OutboundCalling/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: CallAutomation_OutboundCalling
4 |
5 | server:
6 | port: 8080
7 |
8 | acs:
9 | connectionstring:
10 | basecallbackuri:
11 | callerphonenumber:
12 | targetphonenumber:
13 | cognitiveServiceEndpoint:
14 | targetTeamsUserId: <(OPTIONAL) YOUR TARGET TEAMS USER ID ex. "ab01bc12-d457-4995-a27b-c405ecfe4870">
15 |
--------------------------------------------------------------------------------
/CallAutomation_OutboundCalling/static/OutboundCallDesign.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/communication-services-java-quickstarts/347650175630885e4d877ba32d72cc7f2c1de9d6/CallAutomation_OutboundCalling/static/OutboundCallDesign.png
--------------------------------------------------------------------------------
/CallRecording/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.5.1
10 |
11 |
12 | com.communication.callautomation
13 | callrecording
14 | 1.0-SNAPSHOT
15 |
16 | callrecording
17 |
18 | http://www.example.com
19 |
20 |
21 | UTF-8
22 | 1.7
23 | 1.7
24 | 11
25 | v14.17.0
26 | 2.5.2
27 | {docker.image.prefix}
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-web
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-test
38 | test
39 |
40 |
41 | org.apache.httpcomponents
42 | httpclient
43 | 4.5.13
44 |
45 |
46 | com.azure
47 | azure-identity
48 | 1.5.4
49 |
50 |
51 | com.azure
52 | azure-communication-callautomation
53 | 1.0.0
54 |
55 |
56 | com.azure
57 | azure-core
58 | 1.39.0
59 |
60 |
61 | com.azure
62 | azure-messaging-eventgrid
63 | 4.12.1
64 |
65 |
66 | com.azure
67 | azure-cosmos
68 | 4.34.0
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | org.springframework.boot
77 | spring-boot-maven-plugin
78 |
79 |
80 |
81 | org.projectlombok
82 | lombok
83 |
84 |
85 |
86 |
87 |
88 | maven-clean-plugin
89 | 3.1.0
90 |
91 |
92 | maven-resources-plugin
93 | 3.0.2
94 |
95 |
96 | maven-compiler-plugin
97 | 3.8.0
98 |
99 |
100 | maven-surefire-plugin
101 | 2.22.1
102 |
103 |
104 | maven-jar-plugin
105 | 3.0.2
106 |
107 |
108 | maven-deploy-plugin
109 | 2.8.2
110 |
111 |
112 | maven-site-plugin
113 | 3.7.1
114 |
115 |
116 | maven-project-info-reports-plugin
117 | 3.0.0
118 |
119 |
120 | org.codehaus.mojo
121 | exec-maven-plugin
122 | 3.0.0
123 |
124 |
125 |
126 | java
127 |
128 |
129 |
130 |
131 | com.communication.callrecording.ApiApplication
132 |
133 |
134 |
135 | org.apache.maven.plugins
136 | maven-install-plugin
137 | 2.5.2
138 |
139 |
140 |
141 |
142 | jib-maven-plugin
143 | com.google.cloud.tools
144 | ${jib-maven-plugin.version}
145 |
146 |
147 | mcr.microsoft.com/java/jre:11-zulu-alpine
148 |
149 |
150 | {docker.image.prefix}/${project.artifactId}
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/CallRecording/src/main/java/com/communication/callrecording/ApiApplication.java:
--------------------------------------------------------------------------------
1 | package com.communication.callrecording;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ApiApplication
8 | {
9 | public static void main( String[] args )
10 | {
11 | SpringApplication.run(ApiApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/CallRecording/src/main/java/com/communication/callrecording/ConfigurationManager.java:
--------------------------------------------------------------------------------
1 | package com.communication.callrecording;
2 |
3 | import java.io.InputStream;
4 | import java.io.InputStreamReader;
5 | import java.io.Reader;
6 | import java.util.Properties;
7 |
8 | public class ConfigurationManager {
9 | private static ConfigurationManager configurationManager = null;
10 | private final Properties appSettings = new Properties();
11 |
12 | private ConfigurationManager() {
13 | }
14 |
15 | // static method to create instance of ConfigurationManager class
16 | public static ConfigurationManager getInstance() {
17 | if (configurationManager == null) {
18 | configurationManager = new ConfigurationManager();
19 | configurationManager.loadAppSettings();
20 | }
21 | return configurationManager;
22 | }
23 |
24 | public void loadAppSettings() {
25 | try {
26 | ClassLoader classLoader = getClass().getClassLoader();
27 | InputStream inputStream = classLoader.getResourceAsStream("config.properties");
28 | assert inputStream != null;
29 | Reader reader = new InputStreamReader(inputStream);
30 | appSettings.load(reader);
31 | reader.close();
32 | } catch (Exception ex) {
33 | System.out.print("\n Loading app settings failed with error - " + ex.getMessage());
34 | }
35 | }
36 |
37 | public String getAppSettings(String key) {
38 | if (!key.isEmpty()) {
39 | return appSettings.getProperty(key);
40 | }
41 | return "";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CallRecording/src/main/resources/config.properties:
--------------------------------------------------------------------------------
1 | Connectionstring=%Connectionstring%
2 | ACSAcquiredPhoneNumber=%ACSAcquiredPhoneNumber%
3 | BaseUri=%BaseUri%
4 | targetPhoneNumber=%targetPhoneNumber%
--------------------------------------------------------------------------------
/DirectRouting/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - Java
5 | products:
6 | - azure
7 | - azure-communication-services
8 | ---
9 |
10 |
11 | # Direct Routing Configuration
12 |
13 | For full instructions on how to build this code sample from scratch, look at [Quickstart: Direct Routing](https://docs.microsoft.com/azure/communication-services/quickstarts/telephony-sms/voice-routing-sdk-config?pivots=programming-language-java)
14 |
15 | ## Prerequisites
16 |
17 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
18 | - [Java Development Kit (JDK)](https://docs.microsoft.com/azure/developer/java/fundamentals/java-jdk-install) version 8 or above
19 | - [Apache Maven](https://maven.apache.org/download.cgi)
20 | - A deployed Communication Services resource and connection string. For details, see [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource).
21 | - Fully Qualified Domain Name (FQDN) and port number of a Session Border Controller (SBC) in operational telephony system.
22 | - [Verified domain name](https://learn.microsoft.com/en-us/azure/communication-services/how-tos/telephony/domain-validation) of the SBC FQDN.
23 |
24 | ## Code Structure
25 |
26 | - **./src/main/java/com/communication/quickstart/App.java:** contains code for managing phone numbers.
27 | - **pom.xml:** Project's Project Object Model, or [POM](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html).
28 |
29 | ## Before running sample code
30 |
31 | 1. Open an instance of PowerShell, Windows Terminal, Command Prompt or equivalent and navigate to the directory that you'd like to clone the sample to.
32 | 2. `git clone https://github.com/Azure-Samples/communication-services-java-quickstarts.git`
33 | 3. With the Communication Services procured in pre-requisites, add connection string in the code at line no 13
34 | ```String connectionString = "https://.communication.azure.com/;accesskey=";```.
35 | 4. Replace FQDNs of contoso.com domain with your FQDNs
36 |
37 |
38 | ## Run the code
39 |
40 | 1. Navigate to the directory containing the pom.xml file and compile the project by using command `mvn clean compile`.
41 | 2. Then, build the package using command `mvn package`.
42 | 3. Run the command to execute the app `mvn exec:java -Dexec.mainClass="com.communication.quickstart.App" -Dexec.cleanupDaemonThreads=false`.
43 |
--------------------------------------------------------------------------------
/DirectRouting/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.communication.quickstart
8 | communication-quickstart
9 | 1.0-SNAPSHOT
10 |
11 | communication-quickstart
12 |
13 |
14 | UTF-8
15 | 1.8
16 | 1.8
17 |
18 |
19 |
20 |
21 | com.azure
22 | azure-communication-phonenumbers
23 | 1.1.0
24 |
25 |
26 |
--------------------------------------------------------------------------------
/DirectRouting/src/main/java/com/communication/quickstart/App.java:
--------------------------------------------------------------------------------
1 | package com.communication.quickstart;
2 |
3 | import com.azure.communication.phonenumbers.siprouting.SipRoutingAsyncClient;
4 | import com.azure.communication.phonenumbers.siprouting.SipRoutingClientBuilder;
5 | import com.azure.communication.phonenumbers.siprouting.models.SipTrunk;
6 | import com.azure.communication.phonenumbers.siprouting.models.SipTrunkRoute;
7 |
8 | import java.util.List;
9 |
10 | import static java.util.Arrays.asList;
11 | import static java.util.Objects.requireNonNull;
12 |
13 | public class App {
14 | public static void main(String[] args) {
15 | System.out.println("Azure Communication Services - Direct Routing Quickstart");
16 |
17 | String connectionString = "https://.communication.azure.com/;accesskey=";
18 | SipRoutingAsyncClient client = new SipRoutingClientBuilder()
19 | .connectionString(connectionString)
20 | .buildAsyncClient();
21 |
22 | listTrunksAndRoutes(client);
23 | setTrunksAndRoutes(client);
24 | listTrunksAndRoutes(client);
25 | updateTrunk(client);
26 | listTrunksAndRoutes(client);
27 |
28 | System.out.println("Finish");
29 | }
30 |
31 | private static void listTrunksAndRoutes(SipRoutingAsyncClient client) {
32 | System.out.println("---------------------");
33 | System.out.println("Listing trunks");
34 | try {
35 | List trunks = requireNonNull(client.listTrunks().byPage().blockFirst()).getValue();
36 | for (SipTrunk trunk : trunks) {
37 | System.out.printf(" %s:%d%n", trunk.getFqdn(), trunk.getSipSignalingPort());
38 | }
39 | if (trunks.isEmpty()) {
40 | System.out.println(" There are no SIP trunks.");
41 | }
42 |
43 | System.out.println("Listing routes");
44 | List routes = requireNonNull(client.listRoutes().byPage().blockFirst()).getValue();
45 | for (SipTrunkRoute route : routes) {
46 | System.out.printf(" %s: \"%s\" -> %s%n", route.getName(), route.getNumberPattern(), String.join(", ", route.getTrunks()));
47 | }
48 | if (routes.isEmpty()) {
49 | System.out.println(" There are no voice routes.");
50 | }
51 | } catch (Exception e) {
52 | e.printStackTrace();
53 | System.err.println("Listing failed");
54 | }
55 | }
56 |
57 | private static void setTrunksAndRoutes(SipRoutingAsyncClient client) {
58 | System.out.println("---------------------");
59 | System.out.println("Setting trunks");
60 | try {
61 | client.setTrunksWithResponse(asList(
62 | new SipTrunk("sbc.us.contoso.com", 1234),
63 | new SipTrunk("sbc.eu.contoso.com", 1234)
64 | )).block();
65 |
66 | System.out.println("Setting routes");
67 | client.setRoutes(asList(
68 | new SipTrunkRoute("UsRoute", "^\\+1(\\d{10})$")
69 | .setTrunks(asList("sbc.us.contoso.com")),
70 | new SipTrunkRoute("DefaultRoute", "^\\+\\d+$")
71 | .setTrunks(asList("sbc.us.contoso.com", "sbc.eu.contoso.com"))
72 | )).block();
73 | } catch (Exception e) {
74 | e.printStackTrace();
75 | System.err.println("Setting failed");
76 | }
77 | }
78 |
79 | private static void updateTrunk(SipRoutingAsyncClient client) {
80 | System.out.println("---------------------");
81 | System.out.println("Updating trunk");
82 | try {
83 | client.setTrunk(new SipTrunk("sbc.us.contoso.com", 9876)).block();
84 | } catch (Exception e) {
85 | e.printStackTrace();
86 | System.err.println("Updating failed");
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/LookupNumber/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - Java
5 | products:
6 | - azure
7 | - azure-communication-phonenumbers
8 | - azure-identity
9 | - azure-communication-common
10 | ---
11 |
12 | # Look Up Phone Numbers
13 |
14 | For full instructions on how to build this code sample from scratch, look at [Quickstart: Look Up Phone Numbers](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/telephony/number-lookup?pivots=programming-language-java)
15 |
16 | ## Prerequisites
17 |
18 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
19 | - [Java Development Kit (JDK)](https://docs.microsoft.com/azure/developer/java/fundamentals/java-jdk-install) version 8 or above
20 | - [Apache Maven](https://maven.apache.org/download.cgi)
21 | - An deployed Communication Services resource and connection string. For details, see [Create a Communication Services resource](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/create-communication-resource).
22 |
23 | ## Code Structure
24 |
25 | - **./LookupNumber/src/main/java/com/communication/lookup/quickstart/App.java:** contains code for looking up phone numbers.
26 | - **pom.xml:** Project's Project Object Model, or [POM](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html).
27 |
28 | ## Before running sample code
29 |
30 | 1. Open an instance of PowerShell, Windows Terminal, Command Prompt or equivalent and navigate to the directory that you'd like to clone the sample to.
31 | 2. `git clone https://github.com/Azure-Samples/communication-services-java-quickstarts.git`
32 | 3. With the Communication Services procured in pre-requisites, add connection string as an environment variable named `COMMUNICATION_SERVICES_CONNECTION_STRING`
33 | 4. Decide which lookup you would like to perform, and keep in mind that looking up all the operator details incurs a cost, while looking up only number formatting is free.
34 |
35 | > [!WARNING]
36 | > If you want to avoid incurring a charge, comment out lines 36-48
37 |
38 | ## Run the code
39 |
40 | 1. Navigate to the directory containing the pom.xml file and compile the project by using command `mvn compile`.
41 | 2. Then, build the package using command `mvn package`.
42 | 3. Run the command to execute the app `mvn exec:java -D"exec.mainClass"="com.communication.lookup.quickstart.App" -D"exec.cleanupDaemonThreads"="false" -D"exec.args"=""`. Replace `` with the number you want to use.
43 |
--------------------------------------------------------------------------------
/LookupNumber/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.communication.lookup.quickstart
8 | communication-lookup-quickstart
9 | 1.0-SNAPSHOT
10 |
11 | communication-lookup-quickstart
12 |
13 | http://www.example.com
14 |
15 |
16 | UTF-8
17 | 1.8
18 | 1.8
19 |
20 |
21 |
22 |
23 | junit
24 | junit
25 | 4.11
26 | test
27 |
28 |
29 |
30 | com.azure
31 | azure-communication-common
32 | 1.0.0
33 |
34 |
35 |
36 | com.azure
37 | azure-communication-phonenumbers
38 | 1.2.0
39 |
40 |
41 |
42 | com.azure
43 | azure-identity
44 | 1.2.3
45 |
46 |
47 |
48 | com.azure
49 | azure-core
50 | 1.41.0
51 |
52 |
53 |
54 |
55 |
56 | azure-sdk-for-java
57 | https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-java/maven/v1
58 |
59 | true
60 |
61 |
62 | true
63 |
64 |
65 |
66 |
67 |
68 |
69 | azure-sdk-for-java
70 | https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-java/maven/v1
71 |
72 | true
73 |
74 |
75 | true
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | maven-clean-plugin
86 | 3.1.0
87 |
88 |
89 |
90 | maven-resources-plugin
91 | 3.0.2
92 |
93 |
94 | maven-compiler-plugin
95 | 3.8.0
96 |
97 |
98 | maven-surefire-plugin
99 | 2.22.1
100 |
101 |
102 | maven-jar-plugin
103 | 3.0.2
104 |
105 |
106 | maven-install-plugin
107 | 2.5.2
108 |
109 |
110 | maven-deploy-plugin
111 | 2.8.2
112 |
113 |
114 |
115 | maven-site-plugin
116 | 3.7.1
117 |
118 |
119 | maven-project-info-reports-plugin
120 | 3.0.0
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/LookupNumber/src/main/java/com/communication/lookup/quickstart/App.java:
--------------------------------------------------------------------------------
1 | package com.communication.lookup.quickstart;
2 |
3 | import com.azure.communication.phonenumbers.*;
4 | import com.azure.communication.phonenumbers.models.*;
5 | import com.azure.core.http.rest.*;
6 | import com.azure.core.util.Context;
7 | import com.azure.identity.*;
8 | import java.io.*;
9 | import java.util.ArrayList;
10 |
11 | public class App
12 | {
13 | public static void main( String[] args ) throws IOException
14 | {
15 | System.out.println("Azure Communication Services - Number Lookup Quickstart");
16 |
17 | if (args == null || args.length == 0)
18 | {
19 | throw new IOException("missing phone number argument");
20 | }
21 | String phoneNumber = args[0];
22 |
23 | // This code retrieves your connection string from an environment variable
24 | String connectionString = System.getenv("COMMUNICATION_SERVICES_CONNECTION_STRING");
25 |
26 | PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
27 | .connectionString(connectionString)
28 | .buildClient();
29 |
30 | ArrayList phoneNumbers = new ArrayList();
31 | phoneNumbers.add(phoneNumber);
32 |
33 | // Use the free number lookup functionality to get number formatting information
34 | OperatorInformationResult formattingResult = phoneNumberClient.searchOperatorInformation(phoneNumbers);
35 | OperatorInformation formattingInfo = formattingResult.getValues().get(0);
36 | System.out.println(formattingInfo.getPhoneNumber() + " is formatted "
37 | + formattingInfo.getInternationalFormat() + " internationally, and "
38 | + formattingInfo.getNationalFormat() + " nationally");
39 |
40 | // Use the paid number lookup functionality to get operator specific details
41 | // IMPORTANT NOTE: Invoking the method below will incur a charge to your account
42 | OperatorInformationOptions options = new OperatorInformationOptions();
43 | options.setIncludeAdditionalOperatorDetails(true);
44 | Response result = phoneNumberClient.searchOperatorInformationWithResponse(phoneNumbers, options, Context.NONE);
45 | OperatorInformation operatorInfo = result.getValue().getValues().get(0);
46 |
47 | String numberType = operatorInfo.getNumberType() == null ? "unknown" : operatorInfo.getNumberType().toString();
48 | String operatorName = "an unknown operator";
49 | if (operatorInfo.getOperatorDetails()!= null && operatorInfo.getOperatorDetails().getName() != null)
50 | {
51 | operatorName = operatorInfo.getOperatorDetails().getName();
52 | }
53 | System.out.println(operatorInfo.getPhoneNumber() + " is a " + numberType + " number, operated in "
54 | + operatorInfo.getIsoCountryCode() + " by " + operatorName);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ManageTeamsIdentityMobileAndDesktop/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - Java
5 | products:
6 | - azure
7 | - azure-communication-services
8 | ---
9 |
10 |
11 | # Create and manage Communication access tokens for Teams users in mobile and desktop applications
12 |
13 | This code sample walks you through the process of acquiring a Communication Token Credential by exchanging an Azure AD token of a user with a Teams license for a valid Communication access token.
14 |
15 | This sample application utilizes the [MSAL Java](https://github.com/AzureAD/microsoft-authentication-library-for-java) library for authentication against the Azure AD and acquisition of a token with delegated permissions. The token exchange itself is facilitated by the `azure-communication-identity` package.
16 |
17 | To be able to use the token for Calling, use it to initialize the `CommunicationTokenCredential` from the `azure-communication-common` library.
18 |
19 | ## Prerequisites
20 |
21 | - An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
22 | - Java Development Kit (JDK) version 8 or above.
23 | - An active Communication Services resource and connection string. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource/).
24 | - Azure Active Directory tenant with users that have a Teams license.
25 |
26 | ## Before running sample code
27 |
28 | 1. Complete the [Administrator actions](https://docs.microsoft.com/azure/communication-services/quickstarts/manage-teams-identity?pivots=programming-language-javascript#administrator-actions) from the [Manage access tokens for Teams users quickstart](https://docs.microsoft.com/azure/communication-services/quickstarts/manage-teams-identity).
29 | - Take a note of Fabrikam's Azure AD Tenant ID and Contoso's Azure AD App Client ID. You'll need the values in the following steps.
30 | 1. On the Authentication pane of your Azure AD App, add a new platform of the mobile and desktop application type with the Redirect URI of `http://localhost`.
31 | 1. Open an instance of Windows Terminal, PowerShell, or an equivalent command line and navigate to the directory that you'd like to clone the sample to.
32 | 1. `git clone https://github.com/Azure-Samples/communication-services-java-quickstarts.git`
33 | 1. Navigate to the `ManageTeamsIdentityMobileAndDesktop` directory.
34 | 1. With the Communication Services procured in pre-requisites, add connection string, an Azure AD client ID and tenant ID in the App.java file.
35 |
36 | ## Run the code
37 |
38 | From a console prompt, navigate to the directory containing the `pom.xml` file, then execute the following node commands to run the app:
39 |
40 | 1. Compile the project by using command `mvn compile`
41 | 2. Then, build the package using command `mvn package`
42 | 3. Run the command to execute the app `mvn exec:java -Dexec.mainClass="com.communication.quickstart.App" -Dexec.cleanupDaemonThreads=false`. If you are using Powershell CLI try to execute as follow `mvn exec:java -D exec.mainClass="com.communication.quickstart.App" -D exec.cleanupDaemonThreads=false`.
43 |
44 | You should be presented with a browser window and navigated to the Azure AD login form. If the authentication is successful, the application receives an Azure AD access token and exchanges it for a Communication access token.
--------------------------------------------------------------------------------
/ManageTeamsIdentityMobileAndDesktop/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.communication.quickstart
8 | communication-quickstart
9 | 1.0-SNAPSHOT
10 |
11 | communication-quickstart
12 |
13 |
14 | UTF-8
15 | 1.8
16 | 1.8
17 |
18 |
19 |
20 |
21 | com.azure
22 | azure-communication-identity
23 | 1.3.0
24 |
25 |
26 | com.microsoft.azure
27 | msal4j
28 | 1.11.0
29 |
30 |
31 | com.fasterxml.jackson.core
32 | jackson-databind
33 | 2.13.3
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | maven-clean-plugin
43 | 3.1.0
44 |
45 |
46 |
47 | maven-resources-plugin
48 | 3.0.2
49 |
50 |
51 | maven-compiler-plugin
52 | 3.8.0
53 |
54 |
55 | maven-surefire-plugin
56 | 2.22.1
57 |
58 |
59 | maven-jar-plugin
60 | 3.0.2
61 |
62 |
63 | maven-install-plugin
64 | 2.5.2
65 |
66 |
67 | maven-deploy-plugin
68 | 2.8.2
69 |
70 |
71 |
72 | maven-site-plugin
73 | 3.7.1
74 |
75 |
76 | maven-project-info-reports-plugin
77 | 3.0.0
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/ManageTeamsIdentityMobileAndDesktop/src/main/java/com/communication/quickstart/App.java:
--------------------------------------------------------------------------------
1 | package com.communication.quickstart;
2 |
3 | import com.azure.communication.identity.CommunicationIdentityClient;
4 | import com.azure.communication.identity.CommunicationIdentityClientBuilder;
5 | import com.azure.communication.identity.models.GetTokenForTeamsUserOptions;
6 | import com.azure.core.credential.AccessToken;
7 | import com.microsoft.aad.msal4j.IAuthenticationResult;
8 | import com.microsoft.aad.msal4j.InteractiveRequestParameters;
9 | import com.microsoft.aad.msal4j.PublicClientApplication;
10 |
11 | import java.net.URI;
12 | import java.util.HashSet;
13 | import java.util.Set;
14 |
15 | public class App {
16 |
17 | public static void main( String[] args ) throws Exception {
18 | System.out.println("Azure Communication Services - Communication access token Quickstart");
19 | // Quickstart code goes here
20 |
21 | // You need to provide your Azure AD client ID and tenant ID
22 | String appId = "";
23 | String tenantId = "";
24 | String authority = "https://login.microsoftonline.com/" + tenantId;
25 |
26 | // Create an instance of PublicClientApplication
27 | PublicClientApplication pca = PublicClientApplication.builder(appId)
28 | .authority(authority)
29 | .build();
30 |
31 | String redirectUri = "http://localhost";
32 | Set scope = new HashSet();
33 | scope.add("https://auth.msft.communication.azure.com/Teams.ManageCalls");
34 | scope.add("https://auth.msft.communication.azure.com/Teams.ManageChats");
35 |
36 | // Create an instance of InteractiveRequestParameters for acquiring the AAD token and object ID of a Teams user
37 | InteractiveRequestParameters parameters = InteractiveRequestParameters
38 | .builder(new URI(redirectUri))
39 | .scopes(scope)
40 | .build();
41 |
42 | // Retrieve the AAD token and object ID of a Teams user
43 | IAuthenticationResult result = pca.acquireToken(parameters).get();
44 | String teamsUserAadToken = result.accessToken();
45 | String[] accountIds = result.account().homeAccountId().split("\\.");
46 | String userObjectId = accountIds[0];
47 | System.out.println("Teams token: " + teamsUserAadToken);
48 |
49 | // You can find your connection string from your resource in the Azure portal
50 | String connectionString = "";
51 |
52 | // Instantiate the identity client
53 | CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder()
54 | .connectionString(connectionString)
55 | .buildClient();
56 |
57 | // Exchange the Azure AD access token of the Teams User for a Communication Identity access token
58 | GetTokenForTeamsUserOptions options = new GetTokenForTeamsUserOptions(teamsUserAadToken, appId, userObjectId);
59 | AccessToken accessToken = communicationIdentityClient.getTokenForTeamsUser(options);
60 | System.out.println("Token: " + accessToken.getToken());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/OutboundCallReminder/readme.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - java
5 | products:
6 | - azure
7 | - azure-communication-services
8 | ---
9 |
10 | # Outbound Reminder Call Sample
11 |
12 | This sample application shows how the Azure Communication Services Server Calling SDK can be used to build IVR related solutions. This sample makes an outbound call to a phone number or a communication identifier and plays an audio message. If the callee presses 1 (tone1), to reschedule an appointment, then the application invites a new participant and then leaves the call. If the callee presses any other key then the application ends the call. This sample application is also capable of making multiple concurrent outbound calls.
13 | The application is a console based application build on Java development kit(JDK) 11.
14 |
15 | ## Getting started
16 |
17 | ### Prerequisites
18 |
19 | - Create an Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/)
20 | - [Java Development Kit (JDK) version 11 or above](https://docs.microsoft.com/azure/developer/java/fundamentals/java-jdk-install)
21 | - [Apache Maven](https://maven.apache.org/download.cgi)
22 | - Create an Azure Communication Services resource. For details, see [Create an Azure Communication Resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource). You'll need to record your resource **connection string** for this sample.
23 | - Get a phone number for your new Azure Communication Services resource. For details, see [Get a phone number](https://docs.microsoft.com/azure/communication-services/quickstarts/telephony-sms/get-phone-number?pivots=platform-azp)
24 | - Download and install [Ngrok](https://www.ngrok.com/download). As the sample is run locally, Ngrok will enable the receiving of all the events.
25 | - (Optional) Create Azure Speech resource for generating custom message to be played by application. Follow [here](https://docs.microsoft.com/azure/cognitive-services/speech-service/overview#try-the-speech-service-for-free) to create the resource.
26 |
27 | > Note: the samples make use of the Microsoft Cognitive Services Speech SDK. By downloading the Microsoft Cognitive Services Speech SDK, you acknowledge its license, see [Speech SDK license agreement](https://aka.ms/csspeech/license201809).
28 |
29 | ### Configuring application
30 |
31 | - Open the config.properities file to configure the following settings
32 |
33 | - Connection String: Azure Communication Service resource's connection string.
34 | - Source Phone: Phone number associated with the Azure Communication Service resource.
35 | - DestinationIdentities: Multiple sets of outbound target and Transfer target. These sets are seperated by a semi-colon, and outbound target and Transfer target in a each set are seperated by a coma.
36 |
37 | Format: "OutboundTarget1(PhoneNumber),TransferTarget1(PhoneNumber/MRI);OutboundTarget2(PhoneNumber),TransferTarget2(PhoneNumber/MRI);OutboundTarget3(PhoneNumber),TransferTarget3(PhoneNumber/MRI)".
38 |
39 | For e.g. "+1425XXXAAAA,8:acs:ab12b0ea-85ea-4f83-b0b6-84d90209c7c4_00000009-bce0-da09-54b7-xxxxxxxxxxxx;+1425XXXBBBB,+1425XXXCCCC"
40 |
41 | - NgrokExePath: Folder path where ngrok.exe is insalled/saved.
42 | - SecretPlaceholder: Secret/Password that would be part of callback and will be use to validate incoming requests.
43 | - CognitiveServiceKey: (Optional) Cognitive service key used for generating custom message
44 | - CognitiveServiceRegion: (Optional) Region associated with cognitive service
45 | - CustomMessage: (Optional) Text for the custom message to be converted to speech.
46 |
47 | ### Run the Application
48 |
49 | - Navigate to the directory containing the pom.xml file and use the following mvn commands:
50 | - Compile the application: mvn compile
51 | - Build the package: mvn package
52 | - Execute the app: mvn exec:java
53 |
--------------------------------------------------------------------------------
/OutboundCallReminder/src/main/java/com/communication/outboundcallreminder/CallConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.communication.outboundcallreminder;
2 |
3 | import com.communication.outboundcallreminder.EventHandler.EventAuthHandler;
4 |
5 | public class CallConfiguration {
6 | public String connectionString;
7 | public String sourceIdentity;
8 | public String sourcePhoneNumber;
9 | public String appBaseUrl;
10 | public String audioFileName;
11 | public String appCallbackUrl;
12 | public String audioFileUrl;
13 | public int maxRetryAttemptCount;
14 |
15 | public CallConfiguration(String connectionString, String sourceIdentity, String sourcePhoneNumber,
16 | String appBaseUrl, String audioFileName, String maxRetryAttemptCount) {
17 | this.connectionString = connectionString;
18 | this.sourceIdentity = sourceIdentity;
19 | this.sourcePhoneNumber = sourcePhoneNumber;
20 | this.appBaseUrl = appBaseUrl;
21 | this.audioFileName = audioFileName;
22 | EventAuthHandler eventhandler = EventAuthHandler.getInstance();
23 | this.appCallbackUrl = appBaseUrl + "/api/outboundcall/callback?" + eventhandler.getSecretQuerystring();
24 | audioFileUrl = appBaseUrl + "/audio/" + audioFileName;
25 | this.maxRetryAttemptCount = Integer.parseInt(maxRetryAttemptCount);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/OutboundCallReminder/src/main/java/com/communication/outboundcallreminder/CommunicationIdentifierKind.java:
--------------------------------------------------------------------------------
1 | package com.communication.outboundcallreminder;
2 |
3 | public enum CommunicationIdentifierKind {
4 | UserIdentity, PhoneIdentity, UnknownIdentity
5 | }
6 |
--------------------------------------------------------------------------------
/OutboundCallReminder/src/main/java/com/communication/outboundcallreminder/ConfigurationManager.java:
--------------------------------------------------------------------------------
1 | package com.communication.outboundcallreminder;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileReader;
6 | import java.io.IOException;
7 | import java.util.Properties;
8 |
9 | public class ConfigurationManager {
10 | private static ConfigurationManager configurationManager = null;
11 | private final Properties appSettings = new Properties();
12 |
13 | private ConfigurationManager() {
14 | }
15 |
16 | // static method to create instance of ConfigurationManager class
17 | public static ConfigurationManager getInstance() {
18 | if (configurationManager == null) {
19 | configurationManager = new ConfigurationManager();
20 | }
21 | return configurationManager;
22 | }
23 |
24 | public void loadAppSettings() {
25 | try {
26 | File configFile = new File("src/main/java/com/communication/outboundcallreminder/config.properties");
27 | FileReader reader = new FileReader(configFile);
28 | appSettings.load(reader);
29 | reader.close();
30 | } catch (FileNotFoundException ex) {
31 | Logger.logMessage(Logger.MessageType.INFORMATION,"Loading app settings failed with error -- > " + ex.getMessage());
32 | } catch (IOException ex) {
33 | Logger.logMessage(Logger.MessageType.ERROR,"Loading app settings failed with error -- > " + ex.getMessage());
34 | }
35 | }
36 |
37 | public String getAppSettings(String key) {
38 | if (!key.isEmpty()) {
39 | return appSettings.getProperty(key);
40 | }
41 | return "";
42 | }
43 | }
--------------------------------------------------------------------------------
/OutboundCallReminder/src/main/java/com/communication/outboundcallreminder/Controllers/OutboundCallController.java:
--------------------------------------------------------------------------------
1 | package com.communication.outboundcallreminder.Controllers;
2 |
3 | import org.springframework.core.io.InputStreamResource;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.MediaType;
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import com.communication.outboundcallreminder.Logger;
10 | import com.communication.outboundcallreminder.EventHandler.EventAuthHandler;
11 | import com.communication.outboundcallreminder.EventHandler.EventDispatcher;
12 | import org.springframework.web.bind.annotation.PathVariable;
13 | import org.springframework.web.bind.annotation.RequestBody;
14 | import org.springframework.web.bind.annotation.RequestMapping;
15 | import org.springframework.web.bind.annotation.RequestParam;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | @RestController
19 | public class OutboundCallController {
20 |
21 | @RequestMapping("/api/outboundcall/callback")
22 | public static String onIncomingRequestAsync(@RequestBody(required = false) String data,
23 | @RequestParam(value = "secret", required = false) String secretKey) {
24 | EventAuthHandler eventhandler = EventAuthHandler.getInstance();
25 |
26 | /// Validating the incoming request by using secret set in app.settings
27 | if (eventhandler.authorize(secretKey)) {
28 | (EventDispatcher.getInstance()).processNotification(data);
29 | } else {
30 | Logger.logMessage(Logger.MessageType.ERROR, "Unauthorized Request");
31 | }
32 |
33 | return "OK";
34 | }
35 |
36 | @RequestMapping("/audio/{fileName}")
37 | public ResponseEntity