Skip to main content

Tunnel

This doc covers the why, where and how the tunnels are used in Ori.

What is tunnel?

  • A tunnel allows you to create a PORT forwarding connection from your machine to any remote server that you can connect to via ssh.

  • It allows you to essentially assign a temporary domain to your local development environment which is useful while building app/services that required a callback URL to work.

  • For Example

    • It is used in local whatsapp development
    • Any channel integration generally expects a working callback domain to send messages, notifications and other webhooks.


We have two types of tunnels

  • Local-Tunnel: This is a generic tunnel mainly used for local WA development right now. In this, you're assigned an individual tunnel which is mapped to a personal ID of yours(phone number in case of WA). This allows you use the local WA number(+9188514-26472) to test your flows with your local OCS. Below is the solution diagram for the same. Solution Diagram
  • Dev Server Tunnel: In this you stop the process(ocs or any process for that matter) on the development server and setup the tunnel such that all the traffic is now being routed from your local ocs process.

Pre-requisites

  • SSH access to the server you need to tunnel to.
  • SSH access to the tunnel controller.
  • Basic understanding on linux commands to start/stop and check logs .via pm2

Local-Tunnel

  • If you don't have a local-tunnel assigned to you, ask the DevOps team to provision it for you.
    • You'll basically be assigned a port and url. For example:
    • for port 2001, your backend url will be https://local-tunnel1-2001.oriserve.com. This means that after connecting to the tunnel, traffic to this domain will be routed through your local ocs(running on port 8080).
    • Similarly, we can have tunnels from range 2001-65536
  • This tunnel will be specific to a user and will be mapped to his/her personal ID, depending on the channel he/she is working on. For example:
    • wa_id(phone number) in case of WA
    • agentID in case of gbm, etc.
  • Refer this for a basic solution diagram.
  • Make sure OCS is running on local on port 8080.
  • Once your tunnel is provisioned and details have been shared with you by the DevOps team. You can run a tunnel command in a separate terminal tab. Be sure to save this command as this will be bound to you.
    • For example, if port 2001 was assigned your tunnel command will be ssh -N -R 127.0.0.1:2001:127.0.0.1:8080 ori-dev@13.235.64.204 and the backend URL will be https://local-tunnel1-2001.oriserve.com
    • Similarly, if port 2009 was assigned your tunnel command will be ssh -N -R 127.0.0.1:2009:127.0.0.1:8080 ori-dev@13.235.64.204 and the backend URL will be https://local-tunnel1-2009.oriserve.com and so on.
  • Once tunnel is created successfully, you can visit your assigned URL and should get the signature Chatbot page of ori. If you don't then there likely was an issue with the tunnel creation. You'll also notice access logs in you local OCS logs.
  • You can disconnect a tunnel by doing ctrl+c on the terminal tab where tunnel is running.

Dev Server Tunnel

  • ssh into the dev server
  • Get the ocs process id
    • pm2 ps
  • Stop ocs process on server
    • pm2 stop id
  • Run ocs on local on port 8080
  • In a separate terminal tab, start tunnel from local
    • ssh -N -R 8080:127.0.0.1:8080 ori-dev@ip
    • You can verify that tunnel is successfully working by hitting the backend URL of the dev server in the browser. If the tunnel is connected as expected, you should see the signature Chatbot page in the browser and you'll notice a hit in your local OCS logs.
  • Once testing is done, make sure to close tunnel. This can be done by doing ctrl+c on the terminal tab where tunnel is running.
  • Make sure to start the process on server again
    • pm2 start id

Note: It is very important that you stop the ocs process on dev server before you create the tunnel and start the process back after you're done.