Skip to main content

Gchat SDK for managing and closing conversations

Project description

GCHAT Close Conversations

This project automates sending alerts and closing inactive conversations on the GCHAT platform, using API integration.

Repository

https://github.com/Gnew-Solucoes-IP-Ltda/gchat-sdk

Features

  • Automatically sends alert messages to inactive contacts.
  • Automatically closes conversations based on configurable criteria.
  • Flexible configuration via environment variables.

Project Structure

.
├── gchat_sdk/
│   ├── controllers/
│   ├── entities/
│   ├── factories/
│   ├── providers/
│   ├── tests/
│   ├── main.py
│   ├── settings.py
│   └── utils.py
├── examples/
│   └── finish_chats.py
├── .env
├── requirements.txt
└── LICENSE

Installation

  1. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    
  2. Install dependencies:

    pip install gchat-sdk
    
  3. Configure environment variables in the .env file:

    URL_API=https://api.gchat.app.br
    TOKEN_API=your_token
    END_CHATS_WITH_ATTENDANTS_LAST_MESSAGE=True
    END_CHATS_WITH_CONTACTS_LAST_MESSAGE=True
    TIMEOUT=1
    ALERT_TIME=0.1
    

Usage

Run the example to send alerts and close inactive conversations:

import os
from dotenv import load_dotenv
from gchat_sdk.controllers.chat_controller import ChatController
from gchat_sdk.providers.chatbot_provider import ChatBotProvider


load_dotenv()


URL_API = os.environ.get('URL_API')
TOKEN_API = os.environ.get('TOKEN_API')

END_CHATS_WITH_ATTENDANTS_LAST_MESSAGE = True
END_CHATS_WITH_CONTACTS_LAST_MESSAGE = True
TIMEOUT = 2
ALERT_TIME = 0.1
ALERT_MESSAGE_TEXT = '''
🔔 Olá! Percebemos que você está inativo há algum tempo.
Para otimizar nosso atendimento, esta conversa será encerrada.
Caso precise de algo, é só nos chamar novamente.

👋 Agradecemos o contato e estamos à disposição!
'''

provider = ChatBotProvider(
    base_url=URL_API,
    access_token=TOKEN_API
)
controller = ChatController(provider, ALERT_MESSAGE_TEXT)
data = controller.alert_chats(alert_time_in_hour=ALERT_TIME)
print('send message alert', data)
data = controller.finish_chats(
    END_CHATS_WITH_ATTENDANTS_LAST_MESSAGE, 
    END_CHATS_WITH_CONTACTS_LAST_MESSAGE, 
    TIMEOUT
)
print('closed chats', data)

Testing

Unit tests are located in gchat_sdk/tests/. To run the tests using unittest:

python -m unittest discover gchat_sdk/tests/

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gchat_sdk-0.0.8.tar.gz (14.5 kB view details)

Uploaded Source

File details

Details for the file gchat_sdk-0.0.8.tar.gz.

File metadata

  • Download URL: gchat_sdk-0.0.8.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gchat_sdk-0.0.8.tar.gz
Algorithm Hash digest
SHA256 bec017123c2c5dc9a2e1627f4fad1aaf9f9d2d700372ad4e493450ddc8a547f6
MD5 443c415ddc1be3a57a0ac0401204d9a5
BLAKE2b-256 5eca904883483d27842a32b675f8b7a9d2b06a900193fae5979d77803c3af580

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page