Skip to content

Neurotech-HQ/sarufi-heyoo-blueprint-zip

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sarufi heyoo blueprint

Starter code to integrate sarufi with heyoo. This is a blueprint for deploying sarufi chabot on WhatsApp using WhatsApp Cloud API. In this blueprint, we shall set up a webhook to receive whatsapp messages. There are several ways you can set up a webhook. We shall be working on how to use ngrok and Replit in the deployment.

Whatsapp cloud account

To get started using this blueprint for your sarufi bot, you will need TOKEN and TEST WHATSAPP NUMBER obtained from Facebook Developer Portal.

Here are steps to follow for you to get started:

  • Go to your apps.
  • create an app.
  • Select Business >> Business.
  • It will prompt you to enter basic app informations.
  • It will ask you to add products to your app. Add Whatsapp.
  • Right there you will see a your TOKEN and TEST WHATSAPP NUMBER and its phone_number_id.
  • Lastly verify the number you will be using for testing on the To field.

Deploying the bot

USING NGROK

Make sure you have ngrok installed in your working machine.

Quick setup

Have sarufi package installed on your machine before launching your whatsapp bot.

  • Make Project folder Lets Make a project folder named whatsapp-bot. Navigate into it to create virtual evironment whatsapp-bot-env. Activate the environment and install sarufi.

    Run the command to make the magic happen

    mkdir whatsapp-bot
    cd whatsapp-bot
    python -m venv whatsapp-bot-env
    source  whatsapp-bot-env/bin/activate
  • Clone blueprint and install packages

    git clone https://github.com/Neurotech-HQ/sarufi-heyoo-blueprint.git
    cd sarufi-heyoo-blueprint
    pip3 install -r requirements.txt
  • Create a file named '.env`.

    In your working folder, create .env file to hold environment variables using your text editor.

    With the file created, add the following credentials. With whatsapp cloud api, instructions are at the top where as for sarufi, please read on how to get sarufi credentials.

     SARUFI_API_KEY = Your API KEY
     SARUFI_BOT_ID   = Your Bot Id
     WHATSAPP_TOKEN  = Your Whatsapp token
     PHONE_NUMBER_ID = whatsapp phone number id
  • Once you have environment variables set, you are ready to fire 🚀 your main.py in activated virtual envirnoment.

    1. Fire up your python script
    python3 main.py
    1. Start ngrok
    ngrok http 5000

    Note: keep the port number the same as used in main.py.

  • Finish up.

    After running the command, you will have to copy the url ngrok provides. The url looks like https://xxxxxxxxxxx.ngrok.io.

    With the provided url, follow simple steps at Setting whatsapp webhook.

    Open main.py, copy the VERIFY_TOKEN--> paste into verify token in your whatsapp cloud --> verify and save.

    We are heading a the best part of this journey. Just take time to subscribe to message topic. When done ,you are good to go... fire up your bot in whatsapp by sending text.

    🏁 When done with saving the token and url, go on to text your bot. Check out the sample below.

USING REPLIT

  • Log into your Replit account.

    Fork the repo Whatsapp bot using sarufi API and heyoo into your account.

    Navigate to Tools--> Secrets to create environment variables. We have discussed on how to get whatsapp cloud api at the introduction part where as for sarufi view instructions here get sarufi credentials.

    Create

    Secrete key Description
    PHONE_NUMBER_ID Whatsapp cloud phone ID
    WHATSAPP_TOKEN Your whatsapp token
    SARUFI_API_KEY Your sarufi API KEY
    SARUFI_BOT_ID Your sarufi bot id
  • Run the script

    After creating the secret keys, run your main.py. A small webview window will open up with a url that looks like https://{your repl name}.{your replit username}.repl.co.

    With the url, follow simple steps at Setting whatsapp webhook.

  • Final touches

    Go into your repl, copy the VERIFY_TOKEN --> paste into verify token in your whatsapp cloud --> verify and save.

    We are reaching at a good point with the set-up. Lets subscribe to message topic. When done ,you are good to go... fire 🚀 up your bot in whatsapp by sending text.

Getting Sarufi Credentials

To authorize our chabot, we are are going to use authorization keys from sarufi. Log in into your sarufi account. Go to your Profile on account to get Authorization keys

Sarufi authorazation keys

For Bot ID, Navigate to settings(in your bot)>> copy bot ID.

Setting whatsapp webhook

Navigate to your whatsapp cloud account --> configuration -->(Webhook) edit --> then paste the url into callback url.

For Verify token, open main.py copy the VERIFY_TOKEN --> paste into verify token in your whatsapp cloud --> verify and save.

Web hook setup

Webhook field subscription

After veryfing and saving whatsapp webook, navigate to webhook fields --> click manage to subscribe to message topic.

Webhook fields subscription

Sample Bot test

Navigate to your whatsapp cloud account >> API setup >> scroll down to a field written To. Click manage phone number to add you phone number. Follow instructions till you finish

Click send message to start testing your bot. You will receive a message from your test number which your will use in testing your bot.

Send Test Message to Your Number

You can test WhatsApp by sending a message to your bot.

With a bot deployed in Whatsapp, here is a sample of a pizza bot. Bot deployed in whatsapp

Issues

If you will face any issue, please raise one so as we can fix it as soon as possible

Contribution

If there is something you would like to contribute, from typos to code to documentation, feel free to do so, JUST FORK IT.

Credits

All the credits to

  1. kalebu
  2. Jovine
  3. All other contributors

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%