Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Dec 28, 2023
1 parent 7634e23 commit c9bc52e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
6 changes: 3 additions & 3 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
]
dependencies = [
"python-dotenv>=1.0.0",
"ca-lark-oauth>=0.0.4",
"ca-lark-oauth==0.0.5",
"ca-lark-webhook>=0.0.3",
]
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

anyio==4.2.0
blinker==1.7.0
ca-lark-oauth==0.0.4
ca-lark-oauth==0.0.5
ca-lark-sdk==0.0.7
ca-lark-webhook==0.0.3
certifi==2023.11.17
Expand Down
58 changes: 31 additions & 27 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import os

from connectai.lark.oauth import Server as OauthServer
from connectai.lark.sdk import Bot, MarketBot
from connectai.lark.webhook import LarkServer
from connectai.storage import ExpiredDictStorage


def get_app():
hook = LarkServer()
oauth = OauthServer()
bot = Bot(
app_id=os.environ.get("APP_ID"),
app_secret=os.environ.get("APP_SECRET"),
encrypt_key=os.environ.get("ENCRYPT_KEY"),
verification_token=os.environ.get("VERIFICATION_TOKEN")
)
@hook.on_bot_message(message_type="text", bot=bot)
def on_text_message(bot, message_id, content, *args, **kwargs):
text = content["text"]
print("reply_text", message_id, text)
bot.reply_text(message_id, "reply: " + text)

@oauth.on_bot_event(event_type="oauth:user_info", bot=bot)
def on_oauth_user_info(bot, event_id, user_info, *args, **kwargs):
# oauth user_info
print("oauth", user_info)
return user_info

app = oauth.get_app()
app.register_blueprint(hook.get_blueprint())
return app
from flask import Flask

app = Flask(__name__)

hook = LarkServer(prefix="/api/feishu/hook")
oauth = OauthServer(prefix="/api/feishu/oauth")

bot = Bot(
app_id=os.environ.get("APP_ID"),
app_secret=os.environ.get("APP_SECRET"),
encrypt_key=os.environ.get("ENCRYPT_KEY"),
verification_token=os.environ.get("VERIFICATION_TOKEN"),
)


@hook.on_bot_message(message_type="text", bot=bot)
def on_text_message(bot, message_id, content, *args, **kwargs):
text = content["text"]
print("reply_text", message_id, text)
bot.reply_text(message_id, "reply: " + text)


@oauth.on_bot_event(event_type="oauth:user_info", bot=bot)
def on_oauth_user_info(bot, event_id, user_info, *args, **kwargs):
# oauth user_info
print("oauth", user_info)
return user_info


app.register_blueprint(oauth.get_blueprint())
app.register_blueprint(hook.get_blueprint())
3 changes: 3 additions & 0 deletions server/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())
8 changes: 2 additions & 6 deletions server/server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import os
from dotenv import find_dotenv, load_dotenv
from app import get_app

load_dotenv(find_dotenv())
app = get_app()

import env
from app import app

if __name__ == "__main__":
# gunicorn -w 1 -b :8888 "server:app"
app.run(host=os.environ.get("HOST", "0.0.0.0"), port=os.environ.get("PORT", 8888))

0 comments on commit c9bc52e

Please sign in to comment.