{"id":20547277,"url":"https://github.com/theopenconversationkit/tock-py","last_synced_at":"2025-04-14T10:33:27.954Z","repository":{"id":53677909,"uuid":"277658822","full_name":"theopenconversationkit/tock-py","owner":"theopenconversationkit","description":"Tock client to build conversational stories using Python. ","archived":false,"fork":false,"pushed_at":"2023-07-20T15:09:56.000Z","size":104,"stargazers_count":4,"open_issues_count":10,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:36:40.666Z","etag":null,"topics":["ai","chatbot","opensource","python"],"latest_commit_sha":null,"homepage":"https://doc.tock.ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theopenconversationkit.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}},"created_at":"2020-07-06T22:08:54.000Z","updated_at":"2021-10-09T09:12:48.000Z","dependencies_parsed_at":"2022-09-21T03:02:12.010Z","dependency_job_id":null,"html_url":"https://github.com/theopenconversationkit/tock-py","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theopenconversationkit","download_url":"https://codeload.github.com/theopenconversationkit/tock-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862996,"owners_count":21173913,"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":["ai","chatbot","opensource","python"],"created_at":"2024-11-16T02:07:14.173Z","updated_at":"2025-04-14T10:33:27.934Z","avatar_url":"https://github.com/theopenconversationkit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tock-py\n\nBuild chatbots using Tock and Python\n\n## DISCLAIMERS\n\n - Work in progress\n - Not production ready \n  - not yet implemented\n    - Managing User / conversational context\n    - Testing\n    \n## Prerequisites\n\nRun a Tock bot in API mode\n\nCreate a Bot application using the web connector type in Tock Studio and get your API key\n\n### Environment\n\nWe suggest you to create an isolated Python virtual environment:\n\n    $ python3 -m venv env\n    $ source env/bin/activate\n    \nInstall tock-py on your project\n\n    $ pip install tock-py\n\n## Usage\n\n    import logging\n    import os\n    \n    from tock.bot import TockBot\n    from tock.bus import TockBotBus\n    from tock.story import story\n    \n    logging.basicConfig(\n        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n        level=logging.DEBUG\n    )\n    \n    # First create story that handle \"greetings\" intent\n    @story(\n        intent=\"greetings\",\n        other_starter_intents=[],\n        secondary_intents=[]\n    )\n    def greetings(bus: TockBotBus):\n        bus.send(\"Hello i'm a tock-py bot\")\n    \n    # If decorator @story is not provided, the intention with the function name is user\n    def goodbye(bus: TockBotBus):\n        bus.send(\"Hello i'm a tock-py bot\")\n    \n    # Configure your bot and start it\n    TockBot() \\\n        .register_story(greetings) \\\n        .register_story(goodbye) \\\n        .start_websocket(apikey=os.environ['TOCK_APIKEY'])\n\n\n    # You can also use webhook mode\n    # TockBot() \\\n    #     .register_story(greetings) \\\n    #     .register_story(goodbye) \\\n    #     .start_webhook(\"0.0.0.0\", \"tock-py\", 5000)\n\n# Sentence\n\n    bus.send(\"Hello i'm a tock sentence\")\n    \n# Suggestion\n\n    bus.send(\n        Sentence.Builder(\"Hello i'm a tock sentence\")\n            .add_suggestion(\"with suggestion\")\n            .build()\n    )\n\n# Card with action\n\n    bus.send(\n        Card\n            .Builder()\n            .with_title(\"card title\")\n            .with_sub_title(\"with subtitle\")\n            .with_attachment(\"https://www.sncf.com/themes/sncfcom/img/favicon.png\", AttachmentType.IMAGE)\n            .add_action(\"visit\", \"http://www.sncf.com\")\n            .build()\n    )\n\n# Carousel\n    card = Card \\\n        .Builder() \\\n        .with_title(\"Card title\") \\\n        .with_sub_title(\"wit subtitle\") \\\n        .with_attachment(\"https://www.sncf.com/themes/sncfcom/img/favicon.png\", AttachmentType.IMAGE) \\\n        .add_action(\"visit\", \"http://www.sncf.com\") \\\n        .build()\n        \n    bus.send(\n        Carousel\n            .Builder()\n            .add_card(card)\n            .add_card(card)\n            .add_card(card)\n            .build()\n    )\n    \n# Custom state\n\nYour bot can store custom state data in session\n\n    def greetings(bus):\n        if bus.session.get_item(\"greetings_flag\") is None:\n            bus.send(\"Welcome\")\n        else:\n            bus.send(\"Welcome back\")\n        bus.session.set_item(\"greetings_flag\", True)\n        \nYou can clear session\n\n    def goodbye(bus):\n        bus.session.clear()","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopenconversationkit%2Ftock-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopenconversationkit%2Ftock-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopenconversationkit%2Ftock-py/lists"}