{"id":24800670,"url":"https://github.com/gustavocstl/botstate","last_synced_at":"2025-10-11T05:04:45.171Z","repository":{"id":144213017,"uuid":"270470030","full_name":"gustavocstl/botstate","owner":"gustavocstl","description":"package to create and manage a conversation bot states \u0026 flow","archived":false,"fork":false,"pushed_at":"2020-08-11T23:25:53.000Z","size":78,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T12:52:24.851Z","etag":null,"topics":["bot","chatbot","finite-state-machine","fsm","go","golang","states"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gustavocstl.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":"2020-06-08T00:12:35.000Z","updated_at":"2021-03-16T19:22:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"25e23231-9466-4627-9f75-64760c19e5c7","html_url":"https://github.com/gustavocstl/botstate","commit_stats":null,"previous_names":["gucastiliao/botstate","gustavocstl/botstate"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/gustavocstl/botstate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavocstl%2Fbotstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavocstl%2Fbotstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavocstl%2Fbotstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavocstl%2Fbotstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gustavocstl","download_url":"https://codeload.github.com/gustavocstl/botstate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavocstl%2Fbotstate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006333,"owners_count":26084083,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bot","chatbot","finite-state-machine","fsm","go","golang","states"],"created_at":"2025-01-30T03:28:43.313Z","updated_at":"2025-10-11T05:04:45.142Z","avatar_url":"https://github.com/gustavocstl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Botstate\n\nThe easy way to manage bot states.\n\n[![Build Status](https://travis-ci.com/gucastiliao/botstate.svg?branch=master)](https://travis-ci.com/gucastiliao/botstate)\n[![GoDoc](https://godoc.org/github.com/gucastiliao/botstate?status.svg)](https://pkg.go.dev/github.com/gucastiliao/botstate?tab=doc)\n\n## Simple Bot Flow with Botstate\n![Botstate](docs/botstate.png)\n\n## Examples\n- [Chatbot API with botstate](https://github.com/gucastiliao/example-chatbot-botstate)\n- [Chatbot - See botstate in action](https://web-chatbot-botstate.herokuapp.com/)\n\n## Installation\n\nbotstate requires a Go version with [Modules](https://github.com/golang/go/wiki/Modules) support and uses import versioning. So please make sure to initialize a Go module before installing botstate:\n\n```\ngo mod init\ngo get github.com/gucastiliao/botstate\n```\n\nImport:\n\n```\nimport \"github.com/gucastiliao/botstate\"\n```\n\n## Manage state\n\nTo manage states, botstate have a default client that uses [go-redis](https://github.com/go-redis/redis), but you can make your own client to save state the way you prefer.\n\nYou need to initialize storage with your client.\nThis example is using [go-redis](https://github.com/go-redis/redis) with botstate.DefaultStorage:\n```go\nr := redis.NewClient(\u0026redis.Options{\n    Addr: mr.Addr(),\n})\n\nbotstate.SetStorageClient(botstate.DefaultStorage(r))\n```\n\nIf you have your own client:\n\n```go\nvar myClient botstate.Storager\n\n...\n\nbotstate.SetStorageClient(myClient)\n```\n\n## Simple Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/go-redis/redis/v7\"\n\t\"github.com/gucastiliao/botstate\"\n)\n\nfunc main() {\n\tredis := redis.NewClient(\u0026redis.Options{\n\t\tAddr:     fmt.Sprintf(\"%s:%s\", \"127.0.0.1\", \"6379\"),\n\t\tPassword: \"\",\n\t})\n\n\tbotstate.SetStorageClient(\n\t\tbotstate.DefaultStorage(redis),\n\t)\n\n\tstates := []botstate.State{\n\t\t{\n\t\t\tName:     \"start\",\n\t\t\tExecutes: Start,\n\t\t\tNext:     \"add_product\",\n\t\t},\n\t\t{\n\t\t\tName:     \"add_product\",\n\t\t\tExecutes: AddProduct,\n\t\t\tCallback: CallbackAddProduct,\n\t\t\tNext:     \"confirmation\",\n\t\t},\n\t\t{\n\t\t\tName:     \"confirmation\",\n\t\t\tExecutes: Confirmation,\n\t\t},\n\t}\n\n\tbot := botstate.New(states)\n\tbot.Data.User(111)\n\n\tbot.ExecuteState(\"start\")\n\tmsg := bot.GetMessages()\n\tfmt.Println(msg)\n\t// This print [Hello! Starting...]\n\n\tcurrent, _ := bot.Data.GetCurrentState()\n\t// Current state now is -\u003e add_product\n\t// Because value of State.Next\n\n\tbot.ExecuteState(current)\n\tmsg = bot.GetMessages()\n\tfmt.Println(msg)\n\t// This print [Add Product...]\n\n\tcurrent, _ = bot.Data.GetCurrentState()\n\t// Current state now is -\u003e confirmation\n\n\tbot.ExecuteState(current)\n\tmsg = bot.GetMessages()\n\tfmt.Println(msg)\n\t// This print I'm in callback now and [Confirmation ...]\n\t// The callback is defined in the previous state\n\t// And in this execution is called\n\t// If the callback return true, the execution continue and call Confirmation method\n}\n\n// botstate.Bot have access to current user's data\n// and can manipulate it\nfunc Start(bot *botstate.Bot) bool {\n\tbot.AddMessage([]string{\n\t\t\"Hello!\",\n\t\t\"Starting...\",\n\t})\n\n\treturn true\n}\n\nfunc AddProduct(bot *botstate.Bot) bool {\n\tbot.AddMessage([]string{\n\t\t\"Add Product...\",\n\t})\n\n\treturn true\n}\n\nfunc CallbackAddProduct(bot *botstate.Bot) bool {\n\tfmt.Println(\"I'm in callback now!\")\n\n\treturn true\n}\n\nfunc Confirmation(bot *botstate.Bot) bool {\n\tbot.AddMessage([]string{\n\t\t\"Confirmation...\",\n\t})\n\n\tbot.Data.ResetCurrentState()\n\treturn true\n}\n\n```\n\n## See more\n\n- [Docs](https://pkg.go.dev/github.com/gucastiliao/botstate?tab=doc)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavocstl%2Fbotstate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgustavocstl%2Fbotstate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavocstl%2Fbotstate/lists"}