Inscrivez-vous maintenant pour un meilleur devis personnalisé!

Turbocharge Your Next Webex Teams Proof of Concept and Demo Development

Jul, 11, 2018 Hi-network.com

Use this Script to Turbocharge Webex Teams Bot Development

When I first started developing Webex Teams bots, I immediately was drawn to ngrok for its simplicity and power. It allowed me to rapidly start prototyping my bot and to do quick demos. It was simple to setup up very quickly and has a great Client API set that allowed me to dig into the details if I needed to troubleshoot. This article is not meant to be an extensive tutorial on ngrok, so if you are interested in more information on including it in your workflow, see the following links:

  • 6 awesome reasons to use ngrok when testing webhooks
  • Cisco DevNet Learning Labs -Run a Cisco Spark Bot locally. Note you will need a free Cisco DevNet account to access this link.

Because of the ephemeral nature of the ngrok tunnels, though, it is somewhat of a nuisance to develop your bots because every time you tear down an ngrok tunnel and build it back up at a later time, you end up with a different URL for the webhook. If you've prototyped or demo'd a Webex Teams bot before, then you know that you then have to update the webhook with the new URL. This means going to the developer site and modifying the webhook by hand. The process goes somewhat like this:

  1. Bring up an ngrok tunnel
  2. Go to the Webex Teams website
  3. Update your webhook to the new URL that ngrok just gave you.
  4. Run the demo
  5. Shut down your demo
  6. Rinse, lather and repeat every time you need to bring up the tunnel!

The same basic process is applies when beginning to prototype your bot. Bring up a tunnel, update the webhooks, develop/test, tear down the tunnel, rinse and repeat. Don't forget that you need to use your bot's token rather than your developer token for#3 above. Plus you need to make sure that you don't make any copy/paste mistakes, etc. Yucky, manual work!

Fortunately we can mashup the ngrok Client and Webex Teams API's to do this in a more elegant and automated fashion.

Solution

So the process for automating this is relatively simple, so let's dive in. Typically it is as simple as this:

First, bring up the tunnel using ngrok:
[cc lang="bash"]
./ngrok http 80
[/cc]

You will end up with something along these line as output in the terminal.

ngrok startup output showing status and your new web hook URL.

We then run thengrok-startup.pywith two arguments. The first is the port you want the tunnel to be listening on and the second is the name of the new tunnel.
[cc lang="bash"]
python3 ngrok_startup.py 443 "super_awesome_demo_bot"
[/cc]

which will result in a series of status messages describing what the script is doing:

Expected status messages fromngrok-startup.py.

And we are done. The script used the ngrok Client API to tear down the existing tunnels, create new ones and then update your bot's webhook. Now you able to iterate your bot PoC and then demo it live without going through all those manual steps a bunch of times.

The Code

I know a wall of text isn't very interesting, but you may not be familiar with these specific APIs. So I'm going to walk through the five core functions. The full script can be found on the Cisco SE Github site.

So let's take a looksie at some interesting API nuggets. Since ngrok automatically creates a set of tunnels at startup, in order to start with a clean slate, we will tear those down and create a new set.

The ngrok client API couldn't be easier to use. We start by first getting a list of the open tunnels.

[cc lang="python" width="600

tag-icon Tags chauds: Python CiscoSE @ciscodevnet Sparkbots Cisco Webex Teams ngrok

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.