-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
41 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|