Skip to content

Commit

Permalink
Fix/circular import problem (#35)
Browse files Browse the repository at this point in the history
* ✨ feat: 更新卡片内容时支持其它参数

* 🐛 fix: 修复 handlers.py 和 card_replier 属性类型声明导致的模块循环引用的问题

* upgrade version to 0.17.2

* upgrade version to 0.17.2

---------

Co-authored-by: ginping <[email protected]>
  • Loading branch information
ginping and ginping authored Mar 20, 2024
1 parent 216dd9a commit 9601889
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
16 changes: 10 additions & 6 deletions dingtalk_stream/card_replier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@

import platform, requests, copy, hashlib
from .utils import DINGTALK_OPENAPI_ENDPOINT
from .chatbot import ChatbotMessage
from .stream import DingTalkStreamClient
from .log import setup_default_logger
from enum import Enum, unique

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .chatbot import ChatbotMessage
from .stream import DingTalkStreamClient


class CardReplier(object):

def __init__(self, dingtalk_client: DingTalkStreamClient, incoming_message: ChatbotMessage):
self.dingtalk_client: DingTalkStreamClient = dingtalk_client
self.incoming_message: ChatbotMessage = incoming_message
def __init__(self, dingtalk_client: 'DingTalkStreamClient', incoming_message: 'ChatbotMessage'):
self.dingtalk_client: 'DingTalkStreamClient' = dingtalk_client
self.incoming_message: 'ChatbotMessage' = incoming_message
self.conversation_type = incoming_message.conversation_type
self.open_conversation_id = incoming_message
self.logger = setup_default_logger('dingtalk_stream.handler')

@staticmethod
def gen_card_id(msg):
def gen_card_id(msg: 'ChatbotMessage'):
factor = '%s_%s_%s_%s_%s' % (
msg.sender_id, msg.sender_corp_id, msg.conversation_id, msg.message_id, str(uuid.uuid1()))
m = hashlib.sha256()
Expand Down
15 changes: 8 additions & 7 deletions dingtalk_stream/handlers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import json

from .frames import Headers
from .frames import AckMessage
from .frames import SystemMessage
from .frames import EventMessage
from .frames import CallbackMessage
from .stream import DingTalkStreamClient
from .log import setup_default_logger

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .stream import DingTalkStreamClient

class CallbackHandler(object):
TOPIC_CARD_CALLBACK = '/v1.0/card/instances/callback'

def __init__(self):
self.dingtalk_client: DingTalkStreamClient = None
self.dingtalk_client: 'DingTalkStreamClient' = None
self.logger = setup_default_logger('dingtalk_stream.handler')

def pre_start(self):
Expand All @@ -34,7 +35,7 @@ async def raw_process(self, callback_message: CallbackMessage):

class EventHandler(object):
def __init__(self):
self.dingtalk_client: DingTalkStreamClient = None
self.dingtalk_client: 'DingTalkStreamClient' = None
self.logger = setup_default_logger('dingtalk_stream.handler')

def pre_start(self):
Expand All @@ -56,13 +57,13 @@ async def raw_process(self, event_message: EventMessage):

class SystemHandler(object):
def __init__(self):
self.dingtalk_client: DingTalkStreamClient = None
self.dingtalk_client: 'DingTalkStreamClient' = None
self.logger = setup_default_logger('dingtalk_stream.handler')

def pre_start(self):
return

async def process(self, message):
async def process(self, message: SystemMessage):
return AckMessage.STATUS_OK, 'OK'

async def raw_process(self, system_message: SystemMessage):
Expand Down
2 changes: 1 addition & 1 deletion dingtalk_stream/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION_STRING = '0.17.1'
VERSION_STRING = '0.17.2'

0 comments on commit 9601889

Please sign in to comment.