Initialization
initialize the sdk the first step to use the kindly sdk is to initialize it with your bot key and market slug kindlysdk start(botkey "your bot key", market "your market") you can also specify a language code (defaults to "en" if not provided) kindlysdk start(botkey "your bot key", languagecode "en", market "your market") you can also provide an authentication callback if your bot requires authentication kindlysdk start(botkey "your bot key", languagecode "en", market "your market") { chatid, promise in // generate jwt token // on success, call promise fulfill("jwt token") // on error promise reject(error) } markets (per location settings) bots can serve their ui, greeting, and responses per market the market slug is required â pass the market configured for your bot kindlysdk start(botkey "your bot key", languagecode "en", market "eu") the sdk loads that market's settings and tells the backend which market was picked (so greeting/responses are localized to it) if the market's settings can't be loaded the chat won't load â there is no fallback to another market and no per bot default settings find your market slugs in the kindly platform (settings â general â details & markets) see the markets markets md guide for details change language at runtime you can change the language after initialization using kindlysdk setlanguage("lt") // change to lithuanian this method will call the language switch api update the cached settings refresh ui translations notify all ui components of the language change the language setting will persist across chat sessions until explicitly changed bot switching and reinitialization the sdk intelligently handles bot switching and reinitialization scenarios when you call start() multiple times with different parameters automatic bot key switching when you call start() with a different bot key , the sdk automatically detects the change compares the new bot key with the current one performs cleanup calls kindlychatclient shared disconnect(kickuser false) internally to end the current session resets state clears sdk initialization flags and session data reinitializes connects to the new bot seamlessly // first initialization kindlysdk start(botkey "bot key 1", market "your market") kindlysdk displaychat() // later, switch to different bot automatic cleanup happens kindlysdk start(botkey "bot key 2", market "your market") // sdk handles cleanup internally kindlysdk displaychat() connection state handling when the sdk is disconnected (e g , after calling endchat() ), calling start() with the same bot key will reconnect kindlysdk start(botkey "your bot key", market "your market") kindlysdk displaychat() // later, end the chat kindlysdk endchat() // reconnect with same bot key allowed reconnection kindlysdk start(botkey "your bot key", market "your market") // reconnects instead of skipping kindlysdk displaychat() skipping duplicate initialization the sdk skips initialization only when all conditions are met same bot key still connected (not disconnected) kindlysdk start(botkey "your bot key", market "your market") // this second call will be skipped no changes needed kindlysdk start(botkey "your bot key", market "your market") best practices for bot switching option 1 automatic switching (recommended) // sdk handles cleanup automatically kindlysdk start(botkey "new bot key", market "your market") kindlysdk displaychat() option 2 explicit end then start // explicit control over the lifecycle kindlysdk endchat() then(on dispatchqueue main) { in kindlysdk start(botkey "new bot key", market "your market") kindlysdk displaychat() } both approaches work identically choose based on your preference for explicit vs automatic lifecycle management for more details on authentication, see authentication authentication md