Package: ringcentral-bot-framework
RingCentral chatbot framework for PythonWelcome to the RingCentral Chatbot Framework for Python. This framework dramatically simplifies the process of building a bot to work with Glip, RingCentral's group chat system. It is intended to do most of the heavy lifting for developers, allowing them to focus primarily on the logic and user experience of their bot.FeaturesToken Management- handles the server logic associated with bot authentication, and auth token persistenceEvent Subscribtion- automatically subscribes to bot events, and renews those subscriptions when they expireEasy Customization- modify bot behaviors by editingbot.pyData Persistence- built-in suport for filedb and AWS dynamodb, with fully customizable DB layerTurn-key hosting- built-in suport for AWS lambda to host your botGetting StartedLet's get a local chatbot server up and running so that you can understand how the framework functions. Our first chatbot will be a simple parrot bot that will repeat things back to you. Before we get started, let's get your development environment setup with everything you need.Install PrerequisitesThis framework requires Python3.6+ and Pip3.First we installvirtualenvwhich will create an isolated environment in which to install and run all the python libraries needed by this framework. Using virtualenv will ensure that the libraries installed for this project do not conflict or disrupt the other python projects you are working on.# init projectbin/initsourcevenv/bin/activateNext, we need to runngrok, a tool for routing web requests to a localhost. This is what will allow your local bot in development to receive webhooks from RingCentral. ngrok is a node app and is installed and start as follows:./bin/proxyAfter ngrok has started, it will display the URL when the ngrok proxy is operating. It will say something like:Forwarding https://xxxxx.ngrok.io -> localhost:9898Make note of this URL, as you will need it in the next step.Create Your Bot AppYou will need to create your Bot App in RingCentral. Clicking the link, "Create Bot App" below will do this for you. Remember to selectmessagging botbot and forAll RingCentral customers, When you click it, you will to enter in theOAuth Redirect URIfor the bot. This will be the ngrok URL above, plus/bot-oauth. For example:https://xxxxxx.ngrok.io/bot-oauthCreate Bot AppWhen you are finished creating your Bot Application, make note of the Client ID and Client Secret. We will use those values in the next step.Edit .envA sample .env file can be found in.env.sample. Create a copy of this file:cp.sample.env.envThen look for the following variables, and set them accordingly:RINGCENTRAL_BOT_SERVERRINGCENTRAL_BOT_CLIENT_IDRINGCENTRAL_BOT_CLIENT_SECRETInstall Bot BehaviorsThis bot framework loads all bot behaviors from a file calledconfig.py. Let's copy the parrot bot config to get started.cpsample-bots/parrot.py./bot.pyStart the Server# rcs is cli server module from ringcentral_chatbot_serverrcsbot.pyAdd Bot to GlipWhen the server is up and running, you can add the bot to your sandbox Glip account. Navigate the dashboard for the app you created above. Select "Bot" from the left-hand sidebar menu. Save a preferred name for your bot, then click the "Add to Glip" button.Send a Test MessageAfter the bot is added, we can message with it. Login to oursandbox Glip. Then start a chat with the bot using the name you chose in the previous step.You should now be in private chat session with the bot. It should greet you with a message similar to:Hello, I am a chatbot. Please reply "ParrotBot" if you want to talk to me.Type@ParrotBot Polly want a cracker?and let's see what happens.Quick start: Init a bot project with one line scriptNow you know how it works, you may try to init a bot project in one line script:# make sure you have python3.6+ and pip3 installed# use wgetwget-qO-https://raw.githubusercontent.com/ringcentral/ringcentral-chatbot-factory-py/master/bin/init.sh|bash# or with curlcurl-o-https://raw.githubusercontent.com/ringcentral/ringcentral-chatbot-factory-py/master/bin/init.sh|bashA video to show the process:https://youtu.be/x5sTrj5xSN8Example bot appsThe following bots were created using this framework, and should serves as guides as you develop your own original bot.date-time-chatbot: simple Glip chatbot that can tell time/date.assistant-bot: simple assistant Glip bot to show user/company information, this bot will show you how to access user data.poll-bot: Glip poll bot, this bot will show you how to create/use custom database wrapper.translate-bot: translate bot for glip.welcome-bot: Glip chatbot to welcome new team member.at-all-bot: Add AT all function to glip with this bot.Advanced TopicsAdaptive cards supportChecksample-bots/parrot-adaptive-card.pyas an example,Usebot.sendAdaptiveCardto send AdaptiveCardUsebot.updateAdaptiveCardto update AdaptiveCardInteractive messageSince we supportadaptive cards, we also support interactive messages when using adaptive cards actions, so bot can get interactive messages directly from user actions, you need goto app setting page indeveloper.ringcentral.com, enableInteractive Messages, and sethttps://xxxxx.ngrok.io/interactiveasOutbound Webhook URLChecksample-bots/interactive.pyas an example, define your ownonInteractiveMessagefunction to handle interative messages.Hidden commandsPost message@Bot __rename__ newNameto rename bot tonewNamePost message@Bot __setAvatar__and image attachment to set bot profile image.Use CLI tool to create a bot appTheringcentral-chatbot-factory-pywas created to help speed up the process of creating additional Glip bots. To use it, install it, then run thercfcommand as shown below:pip3installringcentral_chatbot_factory
rcfmy-ringcentral-chat-botThen just answer the prompts. Then follow the directions inmy-ringcentral-chat-bot/README.mdto get up and running.Deploy to AWS LambdaUse or write extensionsDirect UseUnit Testbin/testTodosVisithttps://github.com/zxdong262/ringcentral-chatbot-python/issuesCreditsThe core bot framework logic is implanted fromringcentral-ai-botwritten by@tylerlongLicenseMIT