A comprehensive MERN stack (MongoDB, Express.js, React, Node.js) application that demonstrates how to integrate with the Webex Contact Center Audio Files API. This full-stack web application enables administrators to manage .wav audio files that can be played to customers in queues or during call hold scenarios in Webex Contact Center environments.
This sample demonstrates how to use the Webex Contact Center Audio Files API to:
- Upload audio files (.wav format) to your Webex Contact Center organization
- List existing audio files with metadata and playback controls
- Update audio file properties such as name and description
- Delete audio files from your organization
- OAuth authentication integration with Webex Contact Center
- Real-time file management with modern React UI
- Secure API integration using proper authentication flows
This application integrates with Webex Contact Center to manage audio files that can be:
- Played to customers when calls are queued until distributed to available agents
- Integrated into Routing Strategies for hold music
- Used for various customer experience scenarios
- Node.js: Version 14+ from nodejs.org
- MongoDB: Local instance or cloud service like MongoDB Atlas
- Webex Contact Center: Administrator role and developer sandbox access
- Webex Integration: Registered integration with proper scopes
- Register Integration: Go to Webex Contact Center Developer Portal
- Sign in with your Webex account
- Navigate to: My Webex Apps from the menu under your avatar
- Create Integration with:
- Required Scopes:
cjp:config_writeANDcjp:config_readANDopenidANDemailANDprofile - Redirect URI:
http://localhost:5173/oauth(for development)
- Required Scopes:
- Save your Client ID and Client Secret (shown only once!)
Administrator Role Required: You need administrator privileges to manage audio files. Get a developer sandbox here.
-
Clone the repository:
git clone https://github.com/Joezanini/audio_files_int_wxcc.git cd audio_files_int_wxcc -
Configure environment variables:
cp .env.example .env
Edit
.envwith your values:MONGO_URI=mongodb+srv://YOURCLUSTER.mongodb.net/ PORT=5000 CLIENT_ID=YOUR_WXCC_CLIENTID CLIENT_SECRET=YOUR_WXCC_CLIENTSECRET REDIRECT_URI=http://localhost:5173/oauth
-
Update OAuth URL in
frontend/src/pages/Home.jsx:const oauthApi = 'https://webexapis.com/v1/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A5173%2Foauth&scope=spark%3Akms%20cjp%3Aconfig_write%20cjp%3Aconfig_read%20openid%20email%20profile&state=set_state_here';
-
Install dependencies and start backend:
npm install npm run dev
-
Install frontend dependencies and start (new terminal):
cd frontend npm install npm run dev -
Access the application: Open your browser to the URL shown in terminal (typically
http://localhost:5173)
audio_files_int_wxcc/
βββ backend/ # Express.js backend server
β βββ config/ # Database configuration
β βββ controllers/ # API endpoint controllers
β β βββ audiofile.controller.js # Audio file CRUD operations
β βββ models/ # MongoDB models
β βββ routes/ # API routes
β β βββ audiofile.route.js # Audio file endpoints
β β βββ user.route.js # User authentication routes
β βββ utils/ # Utility functions
β βββ server.js # Main server file
βββ frontend/ # React frontend application
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Application pages
β β β βββ Home.jsx # Login/OAuth entry point
β β β βββ OAuth.jsx # OAuth callback handler
β β β βββ Audiofiles.jsx # Audio files management
β β β βββ Upload.jsx # File upload interface
β β β βββ Update.jsx # File update interface
β β βββ store/ # State management
β β βββ App.jsx # Main React application
β βββ vite.config.js # Vite configuration
β βββ package.json # Frontend dependencies
βββ .env.example # Environment variables template
βββ package.json # Backend dependencies
βββ README.md # This file
| Operation | Endpoint | Description | Implementation |
|---|---|---|---|
| Create | POST /organization/{orgid}/audio-file |
Upload new audio file | createAudioFile() |
| List | GET /organization/{orgid}/v2/audio-file |
Retrieve all audio files | listAudioFiles() |
| Update | PATCH /organization/{orgid}/audio-file/{id} |
Partially update file metadata | patchAudioFile() |
| Delete | DELETE /organization/{orgid}/audio-file/{id} |
Remove audio file | deleteAudioFile() |
The application uses OAuth 2.0 authorization code flow:
- Redirect to Webex: User clicks "Login with Webex"
- User Authorization: Webex prompts for permission
- Authorization Code: Webex redirects with code
- Token Exchange: Backend exchanges code for access token
- API Access: Use token for Webex Contact Center API calls
- React 19: Modern UI framework with hooks
- Chakra UI: Component library for consistent design
- React Router: Client-side routing
- Zustand: Lightweight state management
- Vite: Fast development and build tool
- Home Page: OAuth login entry point with Webex branding
- Audio Files Manager: List, play, and manage uploaded files
- Upload Interface: Drag-and-drop file upload with validation
- Update Modal: Edit file metadata and properties
- Responsive Design: Works on desktop and mobile devices
// OAuth redirect in Home.jsx
const oauthApi = 'https://webexapis.com/v1/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A5173%2Foauth&scope=spark%3Akms%20cjp%3Aconfig_write%20cjp%3Aconfig_read%20openid%20email%20profile';
function redirectOauth() {
location.href = oauthApi;
}cjp:config_write: Create and modify audio filescjp:config_read: Read audio file informationopenid: OpenID Connect authenticationemail: User email accessprofile: User profile information
// server.js - Main server setup
import express from 'express'
import dotenv from 'dotenv'
import { connectDB } from './config/db.js';
import audiofileRoutes from "./routes/audiofile.route.js";
const app = express();
app.use(express.json());
app.use("/api/audiofiles", audiofileRoutes);// audiofile.route.js - Multer configuration
import multer from 'multer';
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });
router.post("/", upload.single('file'), createAudioFile);- MongoDB: Document storage for user data and file metadata
- Mongoose: ODM for schema validation and queries
- Models: User authentication and audio file tracking
// App.jsx - Route structure
<Routes>
<Route path='/' element={<Home/>} />
<Route path='/audiofiles' element={<Audiofiles/>} />
<Route path='/oauth' element={<OAuth/>} />
<Route path='/upload' element={<Upload />} />
<Route path='/update' element={<Update />} />
</Routes>- Zustand: Lightweight state management for user authentication
- React Hooks: Local component state for UI interactions
- Context: Shared authentication state across components
-
Backend Development:
npm run dev # Uses nodemon for auto-restart -
Frontend Development:
cd frontend npm run dev # Vite dev server with HMR
-
Production Build:
cd frontend npm run build npm run preview
- Nodemon: Auto-restart backend on file changes
- Vite: Fast frontend development with Hot Module Replacement
- ESLint: Code linting and formatting
- MongoDB Compass: Database visualization and management
// Example upload implementation
const uploadAudioFile = async (file, metadata) => {
const formData = new FormData();
formData.append('file', file);
formData.append('name', metadata.name);
formData.append('description', metadata.description);
const response = await fetch('/api/audiofiles', {
method: 'POST',
body: formData,
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
return response.json();
};// Example list retrieval
const listAudioFiles = async () => {
const response = await fetch('/api/audiofiles', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
const audioFiles = await response.json();
return audioFiles;
};| Variable | Description | Example |
|---|---|---|
MONGO_URI |
MongoDB connection string | mongodb+srv://cluster.mongodb.net/ |
PORT |
Backend server port | 5000 |
CLIENT_ID |
Webex Contact Center client ID | YOUR_WXCC_CLIENTID |
CLIENT_SECRET |
Webex Contact Center client secret | YOUR_WXCC_CLIENTSECRET |
REDIRECT_URI |
OAuth redirect URI | http://localhost:5173/oauth |
Important: If you change the
PORTfrom 5000, update the proxy configuration infrontend/vite.config.js:
// vite.config.js
export default defineConfig({
server: {
proxy: {
'/api': 'http://localhost:5000' // Update port here
}
}
});| Issue | Solution |
|---|---|
| OAuth redirect fails | Verify redirect URI matches integration settings |
| Upload fails | Check file format (.wav only) and size limits |
| API authentication errors | Confirm scopes and token validity |
| Frontend proxy errors | Ensure backend is running on correct port |
| MongoDB connection fails | Verify connection string and network access |
- Check browser console for JavaScript errors
- Verify environment variables are loaded correctly
- Test API endpoints directly with tools like Postman
- Monitor network tab for failed requests
- Check backend logs for server errors
-
Environment Security:
- Never commit
.envfiles to version control - Use secure environment variable management
- Rotate client secrets regularly
- Never commit
-
Authentication:
- Implement proper token refresh mechanisms
- Add rate limiting to API endpoints
- Validate file uploads thoroughly
-
File Security:
- Scan uploaded files for malware
- Implement file size and type restrictions
- Use secure file storage solutions
- Understand Webex Contact Center: Learn about audio file use cases in contact centers
- Study OAuth Flow: Understand authorization code flow implementation
- Explore MERN Stack: Familiarize yourself with MongoDB, Express, React, Node.js
- Practice API Integration: Work with RESTful APIs and file uploads
- Build Extensions: Add features like batch upload, audio preview, or file conversion
- Webex Contact Center Developer Portal
- Audio Files API Documentation
- Webex Contact Center Sandbox
- OAuth 2.0 Authorization Code Flow
- MongoDB Atlas Documentation
- React Documentation
- Chakra UI Components
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Make your changes and test thoroughly
- Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Submit a pull request
This project is licensed under the terms specified in the LICENSE file.
- Issues: Create an issue in this repository
- Webex Developer Support: Visit Webex Developer Support
- Contact Center Documentation: Check Webex Contact Center Docs
- Community: Join the Webex Developer Community
Repository: https://github.com/Joezanini/audio_files_int_wxcc