Package: sarufi
sarufi-python-sdkSarufi Python SDK to help you interact with SARUFI platformInstallationMake sure you havesarufi packageinstalled on your machine before launching your telegram bot, you can easily install by the following command;gitclonehttps://github.com/Neurotech-HQ/sarufi-python-sdkcdsarufi-python-sdk
sarufi-python-sdk$pythonsetup.pyinstallAuthenticationTo authenticate you're bot, you have to specify your client_id and password for Sarufi Platform just as shown below;>>>fromsarufiimportSarufi>>>sarufi=Sarufi(api_key='your API KEY')Creating a BotTo create you're bot with sarufi, you have to be aware of two importants idea or concepts which isintentsandflow.Here an example on how to create your bot;sarufi.create_bot(name="Athony bot",description="My bot can do a lot",intents={"salamu":["Mambo","Hi","Hello","Niaje"],"contact":["naomba mawasiliano","naomba number","naomba namba","nipe mawasiliano","nipe contact",],},flow={"salamu":{"message":["Hi","Naimani upo salama"],"next":"end"},"contact":{"message":["Ungependa kupata namba ya nani ?"],"next_state":"chukua_namba",},"chukua_namba":{"message":["Namba ya huyo mtu ni 07374734737","Karibu tena !!"],"next_state":"end",},},)Creating a Bot from fileYou can create your bot from a file, Here is an example on how to create your bot from a file;fromsarufiimportSarufisarufi=Sarufi(api_key='your API KEY')if__name__=="__main__":response=sarufi.create_from_file(intents="data/intents.yaml",flow="data/flows.yaml",metadata="data/metadata.yaml",)print(response.data)Updating botUpdating the bot is comparatively similar to creating a bot but this time you have to explicity specify theproject IDof your bot.sarufi.update_bot(name="Athony bot",description="My bot can do a lot",intents={"salamu":["Mambo","Hi","Hello","Niaje"],"contact":["naomba mawasiliano","naomba number","naomba namba","nipe mawasiliano","nipe contact",],},flow={"salamu":{"message":["Hi","Naimani upo salama"],"next":"end"},"contact":{"message":["Ungependa kupata namba ya nani ?"],"next_state":"chukua_namba",},"chukua_namba":{"message":["Namba ya huyo mtu ni 07374734737","Karibu tena !!"],"next_state":"end",},},id=2,)Update a bot from fileYou can update your bot from a file as follows;fromsarufiimportSarufisarufi=Sarufi(api_key='your API KEY')if__name__=="__main__":response=sarufi.update_from_file(id=5,intents="data/intents.yaml",flow="data/flows.yaml",metadata="data/metadata.yaml",)print(response.data)Using it in a conversationHere you have to know the bot ID and also specify your user unique ID;>>>fromsarufiimportSarufi>>>sarufi=Sarufi(api_key='your API KEY')2022-08-2318:30:32,918-root-INFO-Gettingtoken>>>bots=sarufi.bots()2022-08-2318:30:38,223-root-INFO-Gettingbots>>>bots[Bot(id=4,name=iBank),Bot(id=5,name=Maria)]>>>maria=bots[1]>>>maria.respond('Hi')2022-08-2318:30:52,065-root-INFO-Sendingmessagetobotandreturningresponse2022-08-2318:30:54,126-root-INFO-Statuscode:2002022-08-2318:30:54,127-root-INFO-Messagesentsuccessfully{'message':[['vipi uhali gani?'],['umeshindaje?'],['mzima wewe?'],['Hello! u hali gani ?'],['Freshi nambie ?'],['Hi, mzima wewe'],['salama sijui wewe'],['za kwako?'],['Vipi hali yako'],['Uhali gani?']]}>>>maria.respond("mi mzima wa afya")2022-08-2318:31:02,245-root-INFO-Sendingmessagetobotandreturningresponse2022-08-2318:31:04,237-root-INFO-Statuscode:2002022-08-2318:31:04,237-root-INFO-Messagesentsuccessfully{'message':[['Ninafurahi kujua uko salama'],['nimefurahi kusikia kutoka kwako'],['Nipo salama pia, nimefurahi kusikia kutoka kwako'],['Napenda kukuona ukiwa na furaha'],['Nimefurahi kusikia hivyo'],['Salama kabisa'],['Mzima kabisa']]}Get a botQuery a bot by ID>>>fromsarufiimportSarufi>>>sarufi=Sarufi(api_key='your API KEY')>>>maria=sarufi.get_bot(5)2022-08-2318:44:05,473-root-INFO-Gettingtoken>>>mariaBot(id=5,name=Maria)Deleting a botDelete a bot by ID>>>fromsarufiimportSarufi>>>sarufi=Sarufi(api_key='your API KEY')>>>sarufi.delete_bot(5)Issues ?Are you facing any issue with the usage of the package, please raise oneContributorskalebuAnthony Mipawa