diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c340881 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# build/test artifacts +.DS_Store +__pycache__/ +*.pyc +*.pyo +build/ +*.egg-info/ +*.dist-info/ +*.whl +logs/ +*.log +.idea/ +~$* +models/mysql.ddl.sql +*.pid +init/ diff --git a/im_platform/__init__.py b/im_platform/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/im_platform/init.py b/im_platform/init.py new file mode 100644 index 0000000..ee8ec33 --- /dev/null +++ b/im_platform/init.py @@ -0,0 +1,12 @@ +from aiohttp import web +from im_platform.api.webhooks import feishu_webhook, wecom_webhook + +async def init_job(app): + app.router.add_post("/noimapi/feishu", feishu_webhook) + app.router.add_post("/noimapi/wecom", wecom_webhook) + yield + +def load_im_platform(): + add_cleanupctx(init_job) + + diff --git a/im_platform/models/im_tenant.json b/im_platform/models/im_tenant.json deleted file mode 100644 index fa27f27..0000000 --- a/im_platform/models/im_tenant.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "summary": [ - { - "name": "im_tenant", - "title": "IM\u79df\u6237", - "primary": "id", - "catelog": "relation" - } - ], - "fields": [ - { - "name": "id", - "title": "ID", - "type": "str", - "length": 32 - }, - { - "name": "org_id", - "title": "\u7ec4\u7ec7ID", - "type": "str", - "length": 32 - }, - { - "name": "platform", - "title": "\u5e73\u53f0", - "type": "str", - "length": 16 - }, - { - "name": "app_id", - "title": "APPID", - "type": "str", - "length": 64 - }, - { - "name": "app_secret", - "title": "APPSECRET", - "type": "str", - "length": 128 - }, - { - "name": "corp_id", - "title": "\u4f01\u4e1aID", - "type": "str", - "length": 64 - }, - { - "name": "agent_id", - "title": "AgentID", - "type": "str", - "length": 32 - } - ], - "indexes": [ - { - "name": "idx_org", - "idxtype": "index", - "idxfields": [ - "org_id" - ] - } - ] -} \ No newline at end of file diff --git a/im_platform/server.py b/im_platform/server.py deleted file mode 100644 index b946feb..0000000 --- a/im_platform/server.py +++ /dev/null @@ -1,16 +0,0 @@ - -from aiohttp import web -from im_platform.api.webhooks import feishu_webhook, wecom_webhook - -async def init_app(): - app = web.Application() - - app.router.add_post("/webhook/feishu", feishu_webhook) - app.router.add_post("/webhook/wecom", wecom_webhook) - - return app - -if __name__ == "__main__": - import asyncio - app = asyncio.run(init_app()) - web.run_app(app, port=8080) diff --git a/models/im_event_log.json b/models/im_event_log.json new file mode 100644 index 0000000..5f6427b --- /dev/null +++ b/models/im_event_log.json @@ -0,0 +1,99 @@ +{ + "summary":[ + { + "name":"im_event_log", + "title":"IM事件日志", + "primary":"id", + "catelog":"entity" + } + ], + "fields":[ + { + "name":"id", + "title":"ID", + "type":"str", + "length":32, + "nullable":"no", + "comments":"主键" + }, + { + "name":"event_id", + "title":"事件ID", + "type":"str", + "length":64, + "nullable":"no", + "comments":"平台事件ID" + }, + { + "name":"org_id", + "title":"组织ID", + "type":"str", + "length":32, + "nullable":"no", + "comments":"系统组织ID" + }, + { + "name":"platform", + "title":"平台", + "type":"str", + "length":16, + "nullable":"no", + "comments":"feishu wecom" + }, + { + "name":"event_type", + "title":"事件类型", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"事件类型" + }, + { + "name":"im_user_id", + "title":"IM用户ID", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"平台用户ID" + }, + { + "name":"payload", + "title":"事件数据", + "type":"text", + "nullable":"yes", + "comments":"完整事件数据" + }, + { + "name":"status", + "title":"处理状态", + "type":"short", + "nullable":"no", + "default":"0", + "comments":"0未处理 1已处理" + }, + { + "name":"ctime", + "title":"创建时间", + "type":"timestamp", + "nullable":"no", + "comments":"事件时间" + } + ], + "indexes":[ + { + "name":"idx_event", + "idxtype":"unique", + "idxfields":["event_id"] + }, + { + "name":"idx_org", + "idxtype":"index", + "idxfields":["org_id"] + }, + { + "name":"idx_platform", + "idxtype":"index", + "idxfields":["platform"] + } + ] +} diff --git a/models/im_message.json b/models/im_message.json new file mode 100644 index 0000000..5a6046d --- /dev/null +++ b/models/im_message.json @@ -0,0 +1,128 @@ +{ + "summary":[ + { + "name":"im_message", + "title":"IM消息中心", + "primary":"id", + "catelog":"entity" + } + ], + "fields":[ + { + "name":"id", + "title":"ID", + "type":"str", + "length":32, + "nullable":"no", + "comments":"主键" + }, + { + "name":"org_id", + "title":"组织ID", + "type":"str", + "length":32, + "nullable":"no", + "comments":"组织ID" + }, + { + "name":"platform", + "title":"平台", + "type":"str", + "length":16, + "nullable":"no", + "comments":"feishu wecom" + }, + { + "name":"msg_id", + "title":"消息ID", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"平台消息ID" + }, + { + "name":"chat_id", + "title":"会话ID", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"群聊或会话ID" + }, + { + "name":"from_user", + "title":"发送用户", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"发送人" + }, + { + "name":"to_user", + "title":"接收用户", + "type":"str", + "length":64, + "nullable":"yes", + "comments":"接收人" + }, + { + "name":"msg_type", + "title":"消息类型", + "type":"str", + "length":32, + "nullable":"no", + "comments":"text image file markdown" + }, + { + "name":"content", + "title":"消息内容", + "type":"text", + "nullable":"yes", + "comments":"消息体" + }, + { + "name":"direction", + "title":"消息方向", + "type":"short", + "nullable":"no", + "default":"0", + "comments":"0接收 1发送" + }, + { + "name":"status", + "title":"状态", + "type":"short", + "nullable":"no", + "default":"0", + "comments":"0正常 1撤回" + }, + { + "name":"ctime", + "title":"创建时间", + "type":"timestamp", + "nullable":"no", + "comments":"消息时间" + } + ], + "indexes":[ + { + "name":"idx_org", + "idxtype":"index", + "idxfields":["org_id"] + }, + { + "name":"idx_msg", + "idxtype":"index", + "idxfields":["msg_id"] + }, + { + "name":"idx_chat", + "idxtype":"index", + "idxfields":["chat_id"] + }, + { + "name":"idx_user", + "idxtype":"index", + "idxfields":["from_user","to_user"] + } + ] +} diff --git a/models/im_tenant.json b/models/im_tenant.json new file mode 100644 index 0000000..7815149 --- /dev/null +++ b/models/im_tenant.json @@ -0,0 +1,24 @@ +{ + "summary":[ + { + "name":"im_tenant", + "title":"IM租户", + "primary":"id", + "catelog":"relation" + } + ], + "fields":[ + {"name":"id","title":"ID","type":"str","length":32}, + {"name":"org_id","title":"组织ID","type":"str","length":32}, + {"name":"platform","title":"平台","type":"str","length":16}, + {"name":"app_id","title":"APPID","type":"str","length":64}, + {"name":"app_secret","title":"APPSECRET","type":"str","length":128}, + {"name":"corp_id","title":"企业ID","type":"str","length":64}, + {"name":"agent_id","title":"AgentID","type":"str","length":32}, + {"name":"status","title":"状态","type":"short"} + ], + "indexes":[ + {"name":"idx_org","idxtype":"index","idxfields":["org_id"]}, + {"name":"idx_platform","idxtype":"index","idxfields":["platform"]} + ] +} diff --git a/models/im_user_map.json b/models/im_user_map.json new file mode 100644 index 0000000..539cff7 --- /dev/null +++ b/models/im_user_map.json @@ -0,0 +1,16 @@ +{ + "summary":[ + { + "name":"im_user_map", + "title":"IM用户映射", + "primary":"id" + } + ], + "fields":[ + {"name":"id","title":"ID","type":"str","length":32}, + {"name":"org_id","title":"组织ID","type":"str","length":32}, + {"name":"user_id","title":"系统用户","type":"str","length":32}, + {"name":"platform","title":"平台","type":"str","length":16}, + {"name":"im_user_id","title":"IM用户ID","type":"str","length":64} + ] +}