初始化
This commit is contained in:
parent
8e41c53292
commit
9e2ae2785b
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": ".venv/bin/python"
|
||||||
|
}
|
53
app.py
Normal file
53
app.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from dingtalkchatbot.chatbot import DingtalkChatbot
|
||||||
|
from slack_bolt.async_app import AsyncApp
|
||||||
|
from slack_bolt.authorization import AuthorizeResult
|
||||||
|
from slack_sdk.web.async_client import AsyncWebClient
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
# Import the async app instead of the regular one
|
||||||
|
|
||||||
|
|
||||||
|
async def authorize(enterprise_id, team_id, user_id, client: AsyncWebClient, logger):
|
||||||
|
logger.info(f"{enterprise_id},{team_id},{user_id}")
|
||||||
|
# You can implement your own logic here
|
||||||
|
token = os.environ["SLACK_BOT_TOKEN"]
|
||||||
|
return AuthorizeResult.from_auth_test_response(
|
||||||
|
auth_test_response=await client.auth_test(token=token),
|
||||||
|
bot_token=token,
|
||||||
|
)
|
||||||
|
|
||||||
|
# WebHook地址
|
||||||
|
dingtalk_webhook = os.environ["DINGTALK_WEBHOOK"]
|
||||||
|
|
||||||
|
dingtalkbot = DingtalkChatbot(dingtalk_webhook)
|
||||||
|
app = AsyncApp(
|
||||||
|
signing_secret=os.environ["SLACK_SIGNING_SECRET"], authorize=authorize)
|
||||||
|
|
||||||
|
|
||||||
|
@app.event("app_mention")
|
||||||
|
async def event_test(body, say, logger):
|
||||||
|
logger.info(body)
|
||||||
|
await say("What's up?")
|
||||||
|
|
||||||
|
|
||||||
|
@app.command("/hello-bolt-python")
|
||||||
|
async def command(ack, body, respond):
|
||||||
|
await ack()
|
||||||
|
await respond(f"Hi <@{body['user_id']}>!")
|
||||||
|
|
||||||
|
|
||||||
|
@app.message("Heads Up!*")
|
||||||
|
async def redirect(body, logger):
|
||||||
|
logger.info(body)
|
||||||
|
|
||||||
|
|
||||||
|
@app.message("")
|
||||||
|
async def logall(body, logger):
|
||||||
|
logger.debug(body)
|
||||||
|
|
||||||
|
|
||||||
|
# 启动slack监听
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.start(3000)
|
4
example.env
Normal file
4
example.env
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export SLACK_SIGNING_SECRET=***
|
||||||
|
export SLACK_BOT_TOKEN=xoxb-***
|
||||||
|
|
||||||
|
export DINGTALK_WEBHOOK = 'https://oapi.dingtalk.com/robot/send?access_token=这里填写自己钉钉群自定义机器人的token'
|
18
requirements.txt
Normal file
18
requirements.txt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
astroid==2.4.2
|
||||||
|
certifi==2020.12.5
|
||||||
|
chardet==4.0.0
|
||||||
|
DingtalkChatbot==1.5.2
|
||||||
|
idna==2.10
|
||||||
|
isort==5.7.0
|
||||||
|
lazy-object-proxy==1.4.3
|
||||||
|
mccabe==0.6.1
|
||||||
|
pkg-resources==0.0.0
|
||||||
|
pylint==2.6.0
|
||||||
|
requests==2.25.1
|
||||||
|
six==1.15.0
|
||||||
|
slack-bolt==1.2.3
|
||||||
|
slack-sdk==3.2.0
|
||||||
|
toml==0.10.2
|
||||||
|
typed-ast==1.4.2
|
||||||
|
urllib3==1.26.2
|
||||||
|
wrapt==1.12.1
|
7
startup.sh
Normal file
7
startup.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
python -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
source .env
|
||||||
|
pip install -U pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
python app.py
|
Loading…
x
Reference in New Issue
Block a user