Skip to content
Snippets Groups Projects
Commit 0295de34 authored by Alexander Karl Richard Rothschild's avatar Alexander Karl Richard Rothschild
Browse files

first

parents
Branches
No related merge requests found
Pipeline #27328 failed with stages
in 12 minutes and 19 seconds
{"executionPlatform":"Camunda Cloud","executionPlatformVersion":"8.6.0","exporter":{"name":"Camunda Web Modeler","version":"0d4ab51"},"schemaVersion":17,"id":"comp_check","components":[{"label":"Name","type":"textfield","layout":{"row":"Row_07ebdr6","columns":6},"id":"Field_0y6c06l","key":"comp_name","readonly":true},{"label":"Surname","type":"textfield","layout":{"row":"Row_07ebdr6","columns":10},"id":"Field_0a69v7t","key":"comp_surname","readonly":true},{"subtype":"date","dateLabel":"Date of the incident:","type":"datetime","layout":{"row":"Row_0pnc7h6","columns":null},"id":"Field_1c76353","key":"comp_date","readonly":true},{"label":"Please state your issue here:","type":"textfield","layout":{"row":"Row_0pcqyyr","columns":16},"id":"Field_05y3qn6","key":"comp_incident","readonly":true},{"label":"Checked","type":"checkbox","layout":{"row":"Row_07esq3t","columns":null},"id":"Field_1859j4j","key":"checkbox_bepm1d","description":"Complaint Check","validate":{"required":true}}],"type":"default"}
\ No newline at end of file
{"executionPlatform":"Camunda Cloud","executionPlatformVersion":"8.6.0","exporter":{"name":"Camunda Web Modeler","version":"0d4ab51"},"schemaVersion":17,"id":"comp_prop","components":[{"label":"Name","type":"textfield","layout":{"row":"Row_07ebdr6","columns":6},"id":"Field_0y6c06l","key":"comp_name","readonly":true},{"label":"Surname","type":"textfield","layout":{"row":"Row_07ebdr6","columns":10},"id":"Field_0a69v7t","key":"comp_surname","readonly":true},{"subtype":"date","dateLabel":"Date of the incident:","type":"datetime","layout":{"row":"Row_0pnc7h6","columns":null},"id":"Field_1c76353","key":"comp_date","readonly":true},{"label":"Please state your issue here:","type":"textfield","layout":{"row":"Row_0pcqyyr","columns":16},"id":"Field_05y3qn6","key":"comp_incident","readonly":true},{"label":"Proposed Compensation","type":"number","layout":{"row":"Row_1kbwfii","columns":null},"id":"Field_19h9za9","key":"comp_prop","defaultValue":0}],"type":"default"}
\ No newline at end of file
{"executionPlatform":"Camunda Cloud","executionPlatformVersion":"8.6.0","exporter":{"name":"Camunda Web Modeler","version":"0d4ab51"},"schemaVersion":17,"id":"comp_sub","components":[{"label":"Name","type":"textfield","layout":{"row":"Row_07ebdr6","columns":6},"id":"Field_0y6c06l","key":"comp_name"},{"label":"Surname","type":"textfield","layout":{"row":"Row_07ebdr6","columns":10},"id":"Field_0a69v7t","key":"comp_surname"},{"subtype":"date","dateLabel":"Date of the incident:","type":"datetime","layout":{"row":"Row_0pnc7h6","columns":null},"id":"Field_1c76353","key":"comp_date"},{"label":"Please state your issue here:","type":"textfield","layout":{"row":"Row_0pcqyyr","columns":16},"id":"Field_05y3qn6","key":"comp_incident"}],"type":"default"}
\ No newline at end of file
{"executionPlatform":"Camunda Cloud","executionPlatformVersion":"8.6.0","exporter":{"name":"Camunda Web Modeler","version":"0d4ab51"},"schemaVersion":17,"id":"comp_resolving","components":[{"label":"Name","type":"textfield","layout":{"row":"Row_07ebdr6","columns":6},"id":"Field_0y6c06l","key":"comp_name","readonly":true},{"label":"Surname","type":"textfield","layout":{"row":"Row_07ebdr6","columns":10},"id":"Field_0a69v7t","key":"comp_surname","readonly":true},{"subtype":"date","dateLabel":"Date of the incident:","type":"datetime","layout":{"row":"Row_0pnc7h6","columns":null},"id":"Field_1c76353","key":"comp_date","readonly":true},{"label":"Please state your issue here:","type":"textfield","layout":{"row":"Row_0pcqyyr","columns":16},"id":"Field_05y3qn6","key":"comp_incident","readonly":true},{"label":"Checked","type":"checkbox","layout":{"row":"Row_07esq3t","columns":null},"id":"Field_1859j4j","key":"comp_resolved","description":"Resolved","validate":{"required":true}}],"type":"default"}
\ No newline at end of file
Copyright (c) <2024> HU Berlin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
# Customer Complaints Workflow
This project implements a customer complaints management system using Python and Camunda Cloud. It includes functionalities for processing complaints, auto-checking the validity of complaints, and simulating customer interactions.
## File Structure
### 1. `requirements.txt`
Contains the necessary dependencies for the project:
- **asyncio**: Built into Python, no installation required.
- **logging**: Built into Python, no installation required.
- **requests**: Ensure the latest stable version is installed.
- **pyzeebe**: The latest version for interacting with Camunda Cloud.
### 2. `customer_complaints.bpmn`
A BPMN file defining the business process workflow for handling customer complaints.
### 3. `customer_complaints.py`
The main script that:
- Connects to Camunda Cloud.
- Defines task handlers for the workflow, such as accepting or rejecting complaints, auto-checking complaint details, and simulating customer compensation.
- Uses `pyzeebe` to interact with the workflow engine.
## Setup and Usage
### Prerequisites
Ensure you have the following installed:
- Python 3.8 or higher.
- Pip (Python package manager).
### Installation
1. Clone the repository.
2. Install the dependencies by running:
```bash
pip install -r requirements.txt
```
### Configuration
Update the `customer_complaints.py` file with your Camunda Cloud credentials:
- `ZEEBE_CLIENT_ID`
- `ZEEBE_CLIENT_SECRET`
- `CAMUNDA_CLUSTER_ID`
- `CAMUNDA_REGION`
### Running the Application
Execute the main script:
```bash
python customer_complaints.py
```
This starts a Zeebe worker that listens for tasks defined in the BPMN workflow.
## Functionality
The application supports the following tasks:
### Workflow Tasks
1. **Auto Check**: Validates the complaint date and checks for inappropriate language.
2. **DB Reject**: Logs rejected complaints in the database.
3. **DB Accept**: Logs accepted complaints in the database along with compensation details.
4. **Reject**: Notifies the customer that their complaint was rejected.
5. **Accept**: Notifies the customer that their complaint was resolved.
6. **Compensation Payment**: Simulates offering and acceptance of compensation by the customer.
7. **Customer Simulation**: Simulates whether a customer responds to follow-ups.
## Troubleshooting
- Ensure all dependencies are installed correctly.
- Verify Camunda Cloud credentials and cluster information.
- Enable debug-level logging in `customer_complaints.py` for detailed logs:
```python
logging.basicConfig(level=logging.DEBUG)
```
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
For further details, refer to the `customer_complaints.bpmn` file to understand the workflow process and how it integrates with the tasks.
This diff is collapsed.
import asyncio
import logging
from pyzeebe import ZeebeWorker, create_camunda_cloud_channel, Job
from datetime import datetime
import random
# Enable debug-level logging for better troubleshooting
logging.basicConfig()#level=logging.DEBUG)
# Camunda Cloud credentials
ZEEBE_CLIENT_ID = "YOUR_CLIENT_ID"
ZEEBE_CLIENT_SECRET = "YOUR_CLIENT_SECRET"
CAMUNDA_CLUSTER_ID = "YOUR_CLUSTER_ID"
CAMUNDA_REGION = "YOUR_CAMUNDA_REGION" # Ensure the region is correct
# Create a channel for Camunda Cloud
channel = create_camunda_cloud_channel(
client_id=ZEEBE_CLIENT_ID,
client_secret=ZEEBE_CLIENT_SECRET,
cluster_id=CAMUNDA_CLUSTER_ID,
region=CAMUNDA_REGION
)
# Create a worker for processing jobs
worker = ZeebeWorker(channel)
database = []
async def on_error(exception: Exception, job: Job, job_controller=None):
"""
Handle task errors.
"""
print(f"Job {job.type} failed with error: {exception}")
@worker.task(task_type="db_reject", exception_handler=on_error)
def db_reject(name, surname, date, incident):
case = {
"name":name,
"surname":surname,
"date":date,
"complaint":incident,
"rejected": True
}
print(f"case {case} inserted" )
database.append(case)
@worker.task(task_type="db_accept", exception_handler=on_error)
def db_accept(name, surname, date, incident, compensation):
case = {
"name":name,
"surname":surname,
"date":date,
"complaint":incident,
"compensation":compensation,
"rejected": False
}
print(f"case {case} inserted" )
database.append(case)
@worker.task(task_type="reject", exception_handler=on_error)
def reject():
print("Yor Complaint was rejected. Please check the correctness or language.")
@worker.task(task_type="accept", exception_handler=on_error)
def accept():
print("Yor Complaint was resolved. Thank you for your feedback.")
@worker.task(task_type="auto_check", exception_handler=on_error)
def auto_check(date, incident):
accept = True
# Predefined list of inappropriate words
inappropriate_words = {"idiot", "stupid", "dumb", "fool", "hate"}
# Validate the date
try:
input_date = datetime.fromisoformat(date)
if input_date > datetime.now():
print("date in the future")
accept = False
except ValueError:
print("unable to parse the date")
accept = False # Invalid date format
# Validate the incident message
lower_case_message = incident.lower()
if any(word in lower_case_message for word in inappropriate_words):
print("language issues")
accept = False
if lower_case_message == "":
print("no complaint")
accept = False
print("auto check complete")
return {"auto_result":accept}
@worker.task(task_type="comp_pay", exception_handler=on_error)
def comp_pay(amount):
amount = int(amount)
accept = random.random() <= 0.5 #simulates customer acceptance
if not accept:
print("customer refuses compensation")
amount = 0
else:
print("customer accepts compensation")
return {"comp_amount": amount, "comp_acc":accept}
@worker.task(task_type="simulate_customer", exception_handler=on_error)
def compute_wait_time():
decision = random.random() <= 0.5 #simulates if customer answers
return {"answers":decision}
# Run the worker
loop = asyncio.get_event_loop()
loop.run_until_complete(worker.work())
asyncio # Built into Python, no need to include in requirements.txt
logging # Built into Python, no need to include in requirements.txt
pyzeebe # Latest version of pyzeebe
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment