Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adamweeks committed Nov 1, 2024
1 parent 98a7946 commit 6435334
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 128 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
node_modules/
.ruff_cache/
.ruff_cache/

# Python
*.pyc
__pycache__/
venv/
*.env

# Flask
instance/
webex-g2g-python.egg-info/
148 changes: 21 additions & 127 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,147 +1,41 @@
# Webex Samples Template
# Guest to Guest Meeting Facilitator

This is the Webex Samples Template Repository, which must be used for all new code contributions. The Webex Samples Template is a standardized framework that provides contributors to the Webex Samples organization with a consistent and organized approach to creating code contributions. By using the template, contributors can create new repositories that are independent of the original repository's commit history, making it easier to track changes and maintain a clean codebase. The template also includes a sample README and linting tools for standardized code samples. Utilizing the template streamlines the contribution process and ensures consistency across the Webex Samples organization, benefiting contributors and maintaining a well-organized codebase.
The Guest to Guest Meeting Facilitator is a service app that allows users to create and manage Webex meetings on behalf of other users. This project is a reference implementation of the [Service Apps as G2G Meeting Facilitator Guide](https://developer.webex.com/docs/service-apps-as-g2g-meeting-facilitator-guide).

## Table of Contents
![App Screenshot](./app.png)

- [Usage](#usage)
- [Github Actions](#github-actions)
- [Installing Prettier via npm (Local Machine)](#installing-prettier-via-npm-local-machine)
- [Installing and Running Ruff Python Linter](#installing-and-running-ruff-python-linter)
- [Pre-Commit Hooks](#pre-commit-hooks)
- [Skipping Hooks](#skipping-hooks)
- [Thanks!](#thanks)
## Getting Started

## Usage

Using template repos varies from directly forking a repo. The commit history is cleaned, and there is no link to the original repository. This will give your new repository all the framework needed but without the history or link to other repos. It will be easier to track your changes, and your work will not be tied to the repository’s other forks.

To use this template, [follow these directions to create your new repo from the template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). Add your project code to the new repo. Then, reach out to Adam Weeks (adweeks) or Ashton Jordan (ashjorda) to have your new repo added to this Github Organization. All newly created repos are set to private by default. Once all Github actions have passed, and your repo is complete, contact Adam or Ashton for review to make the repo public.

This template repo also contains a sample README (this file), that outlines sections you should include in your README to help properly describe the repo's contents. Additionally, you can utilize the [Standard Readme](https://github.com/RichardLitt/standard-readme) format for your README to ensure consistency and best practices.

1. **Create the repository**: First, create your repo by [following these directions to create your new repo from the template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).

2. **Clone the repository**: Next, clone this repository to your local machine using `git clone`.

3. **Install dependencies**: Install prettier/autopep8 as per the below instructions under "GitHub Actions" section to start linting your codebase.

## Github Actions

This template uses GitHub Actions workflow to enforce commonly accepted coding practices across various file formats. We use [Prettier](https://prettier.io), and [Ruff](https://docs.astral.sh/ruff/linter/) for these linting workflows. These workflows run on every pull request. And before merging is allowed, these workflows must pass. During these workflow checks, none of your code will be modified. These checks are commonly focused on spacing and proper tabbing.

The GitHub Actions workflow plays a crucial role in maintaining code quality and consistency within the project. It automates the process of enforcing coding practices, ensuring that all contributions adhere to the established standards.

Specifically, the workflow performs the following checks:

1. **Prettier Formatting**: Prettier is a code formatter that helps maintain consistent code style across the project. The workflow uses Prettier to check if the code follows the defined formatting rules. If any formatting issues are found, the workflow will fail, indicating that the code needs to be properly formatted. Please review the [`prettier.yml`](.github/workflows/prettier.yml) file to see the configuration and settings for the Prettier action.

2. **Ruff Linting**: Ruff is a Python linter that checks for coding style violations and automatically fixes them. The workflow utilizes Ruff to identify any style issues in Python code. If any violations are detected, the workflow will fail, indicating that the code needs to be corrected. Please review the [`ruff.yml`](.github/workflows/ruff.yml) file to see the configuration and settings for the Ruff action.

By running these checks on every pull request, the GitHub Actions workflow ensures that all contributions meet the required coding standards. This helps maintain a clean and consistent codebase, making it easier for developers to collaborate and understand each other's code. It also reduces the chances of introducing bugs or inconsistencies due to coding style variations.
To get started with this project, you'll need to obtain a service app access token. Follow the steps below to generate the token:

## Installing Prettier via npm (Local Machine)
1. Go to the [Webex Developer Portal](https://developer.webex.com/) and sign in.
2. Navigate to the [Service Apps as G2G Meeting Facilitator Guide](https://developer.webex.com/docs/service-apps-as-g2g-meeting-facilitator-guide) documentation.
3. Follow the instructions in the guide to generate a service app access token with the mandatory scopes `guest-meeting:rw`, `meeting:schedules_read`, `meeting:schedules_write`, and any additional desired scopes.

**Note: Prettier documentation link: (https://prettier.io/docs/en/install.html)**

To format your code locally, run the following:

1. Checking what changes prettier would like to make on all the files within your repo. Before writing them:

```bash
npx prettier . --check
```

2. To write the proposed changes, to ensure the prettier workflow passes. Use the following command:

```bash
npx prettier . --write
```

## Installing and Running Ruff Python Linter

**Note: Ruff Documentation: (https://github.com/astral-sh/ruff)**
To lint your Python code locally, follow these steps:

1. Install ruff:

```bash
pip install ruff
```
## Installation

2. Checking what changes Ruff would like to make on all the files within your repo. Before writing them:
1. Clone the repository:

```bash
ruff check .
git clone
```

3. To write the proposed changes, to ensure the Ruff workflow passes. Use the following command:
2. Install the dependencies:

```bash
ruff check --fix .
pip install -r requirements.txt
```

## Pre-Commit Hooks

This project utilizes Husky and lint-staged to automatically format code on pre-commit hooks.

[Husky](https://github.com/typicode/husky) is a Git hook manager that allows you to run scripts at specific Git lifecycle events. In this project, Husky is configured to run a script before each commit.

[lint-staged](https://github.com/lint-staged/lint-staged) is a tool that allows you to run linters on staged files. It helps ensure that only the relevant files are checked, improving performance. In this project, lint-staged is used in conjunction with Husky to format the code before it is committed.

When you make changes to your code and try to commit them, Husky triggers the lint-staged script. lint-staged then runs the configured linters on the staged files, which in this case includes Prettier and Ruff. Prettier is responsible for formatting the code according to the defined rules, while Ruff checks for style violations in Python code.

By using Husky and lint-staged, this project enforces code formatting and style consistency automatically, reducing the chances of introducing formatting issues or style violations. This ensures that the codebase remains clean and consistent, making it easier for developers to collaborate and maintain the project.

To configure Husky and lint-staged in your own project, you can follow the steps below:
## Usage

1. Install Husky and lint-staged from the dev dependencies:
1. Set the environment variable `WEBEX_ACCESS_TOKEN` to the service app access token generated in the [Getting Started](#getting-started) section.
2. Run the app:

```bash
npm install
```

2. Enable pre-commit hooks by removing the comments from the [.husky/pre-commit](.husky/pre-commit) file:

```
# npx lint-staged
# ruff check --fix .
```

3. Save the changes and commit them to your repository. The pre-commit hooks will now run automatically before each commit, ensuring that the code is properly formatted and styled.

## Skipping Hooks

We know that it might not be optimal to have your code checked for every commit (for example, work in progress commits that will be squashed later). For those occasions, skipping the git hooks might be necessary.

### For a Single Command

Most Git commands include a `-n/--no-verify` option to skip hooks:

```sh
git commit -m "..." -n # Skips Git hooks
```

For commands without this flag, disable hooks temporarily with HUSKY=0:

```shell
HUSKY=0 git ... # Temporarily disables all Git hooks
git ... # Hooks will run again
flask run
```

### For multiple commands

To disable hooks for an extended period (e.g., during rebase/merge):

```shell
export HUSKY=0 # Disables all Git hooks
git ...
git ...
unset HUSKY # Re-enables hooks
```

## Thanks!

We truly appreciate your contribution to the Webex Samples!

Made with <3 by the Webex Developer Relations Team at Cisco
3. Open a browser and navigate to `http://localhost:5000/` to access the app.
4. Create a new meeting by entering the meeting details and clicking the `Create Meeting` button.
5. Create meeting join links for the meeting by entering a guest display name and clicking the `Create Join Link` button.
6. Copy the join links and share it with each of the guests.
Binary file added app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from flask import Flask, send_from_directory, request, jsonify
from dotenv import load_dotenv
import os
from webex import WebexAPI

# Load the environment variables from the .env file
load_dotenv()

access_token = os.getenv('WEBEX_ACCESS_TOKEN')
if not access_token:
raise ValueError("Access token is not set. Please set the WEBEX_ACCESS_TOKEN environment variable.")


app = Flask(__name__, static_folder='static')

webex_api = WebexAPI(access_token)

@app.route('/')
def serve_static():
return send_from_directory(app.static_folder, 'index.html')

@app.route('/api')
def api():
# Your API logic here
return 'Hello, API!'

@app.route('/api/create-meeting', methods=['POST'])
def create_meeting():
# Retrieve the request data
data = request.get_json()
title = data.get('title')
start = data.get('start')
end = data.get('end')

# Your code to create the meeting goes here
try:
meeting = webex_api.create_meeting(title, start, end)
return jsonify(meeting)
except Exception as e:
return jsonify({'error': str(e)})

@app.route('/api/generate-join-link', methods=['POST'])
def generate_join_link():
# Retrieve the request data
data = request.get_json()
meeting_id = data.get('meetingId')
password = data.get('password')
email = data.get('email')
display_name = data.get('displayName')

# Your code to generate the join link goes here
join_link = webex_api.join_meeting(meeting_id, password, email, display_name)

return jsonify(join_link)
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
blinker==1.8.2
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.7
Flask==3.0.3
idna==3.8
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
python-dotenv==1.0.1
requests==2.32.3
urllib3==2.2.2
Werkzeug==3.0.4
Loading

0 comments on commit 6435334

Please sign in to comment.