Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed Apr 14, 2023
2 parents e256938 + 9916afd commit 41e36fe
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Run all pre-commit hooks on all the files.
# Getting only staged files can be tricky in case a new PR is opened
# since the action is run on a branch in detached head state
- name: Install and Run Pre-commit
- name: Install and Run Pre-commit
uses: pre-commit/action@v3.0.0

# With no caching at all the entire ci process takes 4m 30s to complete!
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,4 @@ rocket_connect/media/
# end managed by open-wa

version*
mongodb_version*
mongodb_version*
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
exclude: '^docs/|/migrations/|node_modules|migrations|.git|.tox|emojipy|.dot|emojipy'
exclude: "^docs/|/migrations/|^emojipy"
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py39-plus]
args: [--py310-plus]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
args: ["--config=setup.cfg"]
Expand Down
2 changes: 1 addition & 1 deletion merge_production_dotenvs_in_dotenv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from collections.abc import Sequence
from pathlib import Path
from typing import Sequence

import pytest

Expand Down
2 changes: 1 addition & 1 deletion rocket_connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.1.9"
__version__ = "1.1.20"
__version_info__ = tuple(
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
Expand Down
1 change: 0 additions & 1 deletion rocket_connect/asterisk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Call(models.Model):

unique_id = models.CharField(max_length=50, unique=True)
previous_call = models.ForeignKey(
"self", on_delete=models.CASCADE, null=True, blank=True
Expand Down
2 changes: 0 additions & 2 deletions rocket_connect/instance/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def alert_last_message_open_chat(
context = Context(context_dict)
template = Template(notification_template)
for target in notification_target.split(","):

# render message
message = template.render(context)
if target.startswith("#"):
Expand All @@ -89,7 +88,6 @@ def alert_last_message_open_chat(
text=message, channel=target.replace("#", "")
)
else:

# target may contain variables
target_template = Template(target)
rendered_target = target_template.render(context)
Expand Down
1 change: 0 additions & 1 deletion rocket_connect/instance/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_get_close_message(self):
self.assertEqual(close_message, self.incoming.get_close_message())

def test_get_advanced_close_message(self):

# test advanced forced message
forced_dpto1 = "Forced Message for Dpto 1"
forced_dpto2 = "Forced Message for Dpto 2"
Expand Down
7 changes: 4 additions & 3 deletions rocket_connect/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ def get_room(
# optionally allow welcome message
if allow_welcome_message:
if self.config.get("welcome_message"):

# only send welcome message when
# 1 - open_room is False and there is a welcome_message
# 2 - open_room is True, room_created is True and there is a welcome_message
Expand Down Expand Up @@ -690,8 +689,10 @@ def decrypt_media(self, message_id=None):

def close_room(self):
if self.room:
# close all room from connector with same room_id
self.connector.rooms.filter(room_id=self.room.room_id).update(open=False)
# close all room from this server with same room_id
LiveChatRoom.objects.filter(
connector__server=self.connector.server, room_id=self.room.room_id
).update(open=False)
self.post_close_room()

def post_close_room(self):
Expand Down
1 change: 0 additions & 1 deletion rocket_connect/plugins/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def change_agent_name(self, agent_name):


class ConnectorConfigForm(BaseConnectorConfigForm):

access_token = forms.CharField(
help_text="Facebook Access Token to get contact info",
required=False,
Expand Down
1 change: 0 additions & 1 deletion rocket_connect/plugins/instagram_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def get_incoming_message_id(self):


class ConnectorConfigForm(BaseConnectorConfigForm):

access_token = forms.CharField(
help_text="Facebook Access Token to get contact info",
required=False,
Expand Down
3 changes: 0 additions & 3 deletions rocket_connect/plugins/metacloudapi_whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class Connector(ConnectorBase):

# main incoming hub
def incoming(self):
"""
Expand Down Expand Up @@ -121,7 +120,6 @@ def handle_challenge(self):
return HttpResponseForbidden()

def handle_message(self):

if self.message.get("type") == "unsupported":
# do nothing
return JsonResponse({"message": "unsupported type"})
Expand Down Expand Up @@ -352,7 +350,6 @@ def status_session(self):


class ConnectorConfigForm(BaseConnectorConfigForm):

graph_url = forms.CharField(
help_text="Facebook GraphQl endpoint with version, eg https://graph.facebook.com/v14.0/",
required=True,
Expand Down
33 changes: 18 additions & 15 deletions rocket_connect/plugins/wppconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytz
import requests
import urllib3
import vobject
from django import forms
from django.conf import settings
Expand Down Expand Up @@ -63,20 +64,23 @@ def status_session(self):
self.config.get("instance_name"),
)
session = self.get_request_session()
status_req = session.get(endpoint, timeout=1)
if status_req.ok:
status = status_req.json()
# if connected, get battery and host device
if status.get("status") == "CONNECTED":
# host device
endpoint = "{}/api/{}/host-device".format(
self.config.get("endpoint"),
self.config.get("instance_name"),
)
host_device = session.get(endpoint, timeout=1).json()
status["host_device"] = host_device["response"]
else:
status = {"success": False, **status_req.json()}
try:
status_req = session.get(endpoint, timeout=1)
if status_req.ok:
status = status_req.json()
# if connected, get battery and host device
if status.get("status") == "CONNECTED":
# host device
endpoint = "{}/api/{}/host-device".format(
self.config.get("endpoint"),
self.config.get("instance_name"),
)
host_device = session.get(endpoint, timeout=1).json()
status["host_device"] = host_device["response"]
else:
status = {"success": False, **status_req.json()}
except urllib3.exceptions.ReadTimeoutError as e:
status = {"success": False, "message": str(e)}

return status

Expand Down Expand Up @@ -1253,7 +1257,6 @@ def handle_ack_fromme_message(self):


class ConnectorConfigForm(BaseConnectorConfigForm):

webhook = forms.CharField(
help_text="Where WPPConnect will send the events",
required=True,
Expand Down
1 change: 0 additions & 1 deletion rocket_connect/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@admin.register(User)
class UserAdmin(auth_admin.UserAdmin):

form = UserChangeForm
add_form = UserCreationForm
fieldsets = (
Expand Down
4 changes: 2 additions & 2 deletions rocket_connect/users/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any

from django.contrib.auth import get_user_model
from factory import Faker, post_generation
from factory.django import DjangoModelFactory


class UserFactory(DjangoModelFactory):

username = Faker("user_name")
email = Faker("email")
name = Faker("name")
Expand Down
3 changes: 0 additions & 3 deletions rocket_connect/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class UserDetailView(LoginRequiredMixin, DetailView):

model = User
slug_field = "username"
slug_url_kwarg = "username"
Expand All @@ -19,7 +18,6 @@ class UserDetailView(LoginRequiredMixin, DetailView):


class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):

model = User
fields = ["name"]
success_message = _("Information successfully updated")
Expand All @@ -35,7 +33,6 @@ def get_object(self):


class UserRedirectView(LoginRequiredMixin, RedirectView):

permanent = False

def get_redirect_url(self):
Expand Down

0 comments on commit 41e36fe

Please sign in to comment.