{"id":20695676,"url":"https://github.com/ibm-cloud/slack-chatbot-database-watson","last_synced_at":"2025-06-25T22:04:44.730Z","repository":{"id":29034282,"uuid":"119979583","full_name":"IBM-Cloud/slack-chatbot-database-watson","owner":"IBM-Cloud","description":"Code for the solution tutorial \"Build a database-driven Slackbot\" (chatbot) with a custom extension in IBM Watson Assistant","archived":false,"fork":false,"pushed_at":"2024-09-16T11:55:00.000Z","size":472,"stargazers_count":30,"open_issues_count":0,"forks_count":50,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-28T14:02:59.767Z","etag":null,"topics":["db2","ibm-clo","ibm-cloud","ibm-cloud-functions","ibm-cloud-solutions","nodejs","openwhisk","postgresql","python","slack","watson-conversation"],"latest_commit_sha":null,"homepage":"https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-slack-chatbot-database-watson","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IBM-Cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-02T12:34:38.000Z","updated_at":"2024-11-15T04:31:22.000Z","dependencies_parsed_at":"2022-07-27T17:18:57.856Z","dependency_job_id":"765be7b7-7ac7-45b4-a98d-ab9b9df69102","html_url":"https://github.com/IBM-Cloud/slack-chatbot-database-watson","commit_stats":{"total_commits":51,"total_committers":5,"mean_commits":10.2,"dds":0.1568627450980392,"last_synced_commit":"1e5f3112eb74788e68f90c41d9414e8f3fc94b1d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IBM-Cloud/slack-chatbot-database-watson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM-Cloud%2Fslack-chatbot-database-watson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM-Cloud%2Fslack-chatbot-database-watson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM-Cloud%2Fslack-chatbot-database-watson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM-Cloud%2Fslack-chatbot-database-watson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IBM-Cloud","download_url":"https://codeload.github.com/IBM-Cloud/slack-chatbot-database-watson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IBM-Cloud%2Fslack-chatbot-database-watson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261960506,"owners_count":23236572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["db2","ibm-clo","ibm-cloud","ibm-cloud-functions","ibm-cloud-solutions","nodejs","openwhisk","postgresql","python","slack","watson-conversation"],"created_at":"2024-11-17T00:10:26.109Z","updated_at":"2025-06-25T22:04:44.700Z","avatar_url":"https://github.com/IBM-Cloud.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Note:**   \nCode and instructions relating to the previous version of the tutorial [Build a database-driven Slackbot](https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-slack-chatbot-database-watson) are located in the [branch **cloud-functions**](https://github.com/IBM-Cloud/slack-chatbot-database-watson/tree/cloud-functions).\n\n\n# Build a database-driven Slackbot with IBM Watson Assistant\n\nThis repository contains the code for IBM Cloud solution tutorial [Build a database-driven Slackbot](https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-slack-chatbot-database-watson). It uses IBM Watson Assistant to create a chatbot and link it to Slack for a \"Slackbot\". By integrating a custom extension into the assistant, the chatbot can reach out to a Db2 on Cloud database. The custom extension is a Python app which provides a REST API for database objects. The chatbot can retrieve and insert data by calling these API functions. The Python app is deployed to IBM Code Engine.\n\n![Architecture](images/SlackbotArchitecture.svg)\n\n# Run and test locally\n\nThe app was tested with Python 3.10. You can either run the app directly or first build, then run it as container.\nDirect: \n1. Install the required modules as specified in [requirements.txt](requirements.txt).\n2. Edit **.env** to configure the database connection and a secret token / API key.\n3. Run `python3 app.py`\n\nUse the **podman** or **docker** tool to build and run the container.\n1. `docker build -t slackbot:2 .`\n2. Edit **.env** to configure the database connection and a secret token / API key.\n3. `docker run -p 8080:8080 --env-file .env slackbot:2`\n\nThe file [.env.sample](.env.sample) shows a sample configuration:\n- DB2_URI: Has the SQLAlchemy URL to the Db2 database\n- API_TOKEN: Is the secret for the API key authentication.\n- TABLE_ARGS: Is an optional setting to specify a different table schema. The EVENTS table is created in the default schema for the connection. This can be overwritten.\n\n\nIf you stored the Db2 credentials in a file **slackbotkey.json**, then use **jq** to create the URL using this command:\n```\ncat slackbotkey.json | jq '.[].credentials.connection.db2 | (.authentication.username + \":\" + .authentication.password + \"@\" + .hosts[0].hostname + \":\" + (.hosts[0].port | tostring) + \"/\" + .database + \"?Security=SSL\")'\n```\nThe output follows this schema `db2+ibm_db://user:password@hostname.databases.appdomain.cloud:port/bludb?Security=SSL;`.\n\nCreate or recreate the database objects by calling the following API. Adapt the host, port, and API key as necessary.\n```\ncurl -X 'POST'  'http://127.0.0.1:5000/database/recreate?confirmation=True' -H 'accept: application/json' -H 'API_TOKEN: MY_SECRET'\n```\n\n# OpenAPI Specification\nThe Python app is based on the [APIFlask](https://apiflask.com/) API framework which itself is based on Flask. [The OpenAPI specification for the application can be (re-)generated using](https://apiflask.com/openapi/):\n```\nflask spec --output slackbot-openapi-spec.json\n```\n\nYou can also access the running app at the `/docs` (Swagger UI) and `/redoc` (Redoc) endpoints for interactive API documentation. See the [APIFlask documentation on Swagger UI and Redoc](https://apiflask.com/api-docs/) for details.\n\n![Swagger UI](images/SwaggerUI.png)\n\n## License\n\nSee [License.txt](License.txt) for license information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibm-cloud%2Fslack-chatbot-database-watson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibm-cloud%2Fslack-chatbot-database-watson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibm-cloud%2Fslack-chatbot-database-watson/lists"}