TekinBot
TaaS: Tekin (a knowledgeable and possibly friendly professor) as a Slackbot
Install / Use
/learn @nanflasted/TekinBotREADME
Tekinbot
Tekinbot is a simple and expandable slackbot who runs on Python, uWSGI, love, and Slack's Event API, and who could serve great utility to your Slack workspace!
Preparation:
-
You need python3.6, together with MySQL and SQLite
-
First of all, set up a python virtual environment by running
make venv -
Run
make install-hooksto install pre-commit hooks -
git checkout -b <your-branch-name>, and hack away! For this repo, I recommend using a meaningful branch name, and recommend using the formatgit checkout -b <github_username-issue_number-branch_name> -
Run
make devto make a local server instance so you couldcurland test your changes, note that themake devinstance runs with--dry-runand--no-dboptions, meaning that:- it does not send response requests, but instead prints all responses to stdout
- it does not write to mysql database, but uses an in-memory sqlite instance instead
- it is served with python builtin
wsgireflibrary, instead ofuWSGI
you could also run (in venv)
python3 -m tekinbot.tekinwith any options, run with-hor--helpto see the available dev options. -
After making your changes,
git push origin <your-branch-name>, for this repo, let me know that your branch is ready to be merged -
(Optional) If you have a Slack workspace to test it on:
-
get your tekin's slack OAuth tokens and put them in a
tekin-secretsconfig; by default, this config is in~/.tekin-secrets.yaml, you need to have a section in that config likeslack: app_auth: xoxp-long-strings... bot_auth: xoxb-long-strings... tekin_id: <@UTEKIN123>the
tekin_idis the user id string of Tekinbot, it is used for interpreting@TekinBot. You can get this string by adding Tekinbot in your workspace, @TekinBot, then copying the link of @TekinBot. It should look likehttps://<your-workspace>.slack.com/team/UTEKIN123, the last section is thetekin_id. We will try to automate this process by querying Slack API in a future branch.You will also need some database configs in this secrets file, see the Database section below.
For an example of this
tekin-secretsconfig, see here. -
run
make serverand set your event subscription request URL in Slack tohttp://<your-tekin-url>:9338, -
if you want another port, or some other uWSGI server related options, change the uwsgi config at /config/tekin_uwsgi_conf.yaml
-
You can then see your tekinbot addition in live action! EHHHHHHH!
-
-
You've dunnit! Remember what Tekin would say: take a 5 minute break, drink some water and wash your face...
How to add a new module:
-
All current modules can be seen in this directory, if you would like some examples to look at.
-
All the modules should have two methods:
process(request)andpost(request, response). -
Some modules may need extra components; for example, all commands in
messagesubmodule need a component calledcomm_re. Refer to the individual modules' README to see how they work. -
The
process()method handles an incoming message, and decides how to respond to it. Therequestparameter is the full http request generated by Slack. A sample of what it looks like could be seen here -
The
post()method handles how a response should be posted, and any actions that are to be performed after the posting of the said messages. The utility modules have some functions for plain text posting, so usually you could just use these utilities if you are not trying to post special stuff, or to perform some pre/post-posting actions. -
Add your module to the comms/__init__.py, and its individual submodule's __init__.py
-
After implementing writing both of these functions and any other additional requirements that a module might have, you should then write unit tests for your comms module.
-
Commit your changes, fix any things that may be caught by the pre-commit hooks, then
make test; if any of the test fails, fix accordingly. -
Manually Test your module by
make devthencurling your local tekin instance with something similar to the example here.
How to Tekin database:
-
First of all, you will need
mysql-serverrunning on your dev if you want to do any manual testing at all. See here to see how to set it up on Ubuntu environments. This project uses SqlAlchemy ORM to deal with all the database transactions; for a quick tutorial see hereYou will also need to
CREATEa database namedtekinbotin MySQL.If you do not want to give Tekinbot
rootaccess to mysql-server, make a user and configure it intekin-secretsconfig (see above), and make sure toGRANTproper priviledges to the user you created; minimally, CRUD-related priviledges should be given. -
Figure out what kind of tables you will need, and make a table model similar to this one in the same directory (tekinbot/db/models); after you are done writing your table schemas, add your table to the db module
-
Implement your module; tekin uses a singleton as SqlAlchemy
engine, and with that engine creates a singleSessionMaker, to get these instances, use the utilities fromtekinbot.utils.db -
To test on your machine, supply your MySQL-server's access credentials in the
.tekin-secrets.yamlfile, by default it is located at~/.tekin-secrets.yaml, you can change the yaml file to be at a different location, but don't commit it as part of your change; make sure the yaml file a dictionary similar to this:database: username: <your-tekin-user-name> password: hunter2 -
When you
make dev, all the tables in the directory tekinbot/db/models will be initiated if they don't exist yet. Run python, import your module, and test away! Though, do note thatmake devdefaults to use an in-memory sqlite database; to use actual MySQL database, runpython3 -m tekinbot.tekinwithout the--no-dboption. -
For NS's instance of Tekin, if after a feature has been shipped, you need a table model changed, figure out the correct
ALTER TABLEcommand, and include it in your pull request.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
