Posts tagged with chatbot

We are building a chatbot for WhatsApp using the OpenAI API, which is intended to be able to answer any question asked to it. However, we are experiencing some issues when trying to integrate the OpenAI API with the WhatsApp Business API. Here is the code we are using for this integration:

import os import requests from flask import Flask, request import openai from Testbotgpt import generate_response app = Flask(__name__) def send_message(to, text):     data = {         "recipient_type": "individual",     "to": "whatsapp:{}".format(to),     "type": "text",     "text": {       "body": text     }     }     headers = {         'Content-Type': 'application/json',         'Authorization': 'Bearer <Access Token>'     }     api_url = 'https://api.whatsapp.com/v1/messages'     response = requests.post(api_url, json=data, headers=headers)     if response.status_code != 200:                raise ValueError('Error sending message: {}'.format(response.text)) @app.route('/bot', methods=['POST']) def bot():     incoming_msg = request.values.get('Body', '').lower()     from_number = request.values.get('From', '')     responded = False      # Check if the message contains a greeting     if 'hi' in incoming_msg:         send_message(from_number, "Hello! How can I help you today?")         responded = True     elif 'bye' in incoming_msg:         send_message(from_number, "Goodbye! Have a great day.")         responded = True        # Use the GPT model to generate a response based on the user's input     else:         response = generate_response(incoming_msg)         send_message(from_number, response)         responded = True           return 'OK' if __name__ == '__main__':   app.run() 

Could you please help us understand what we are doing wrong and suggest a solution to fix the issue?

I am testing the Single Product Message API endpoint in Whatsapp-Business Cloud.

It is working for some of the products in the catalogue, but for some other products in the same catalogue giving error as 'product not found for product_retailer_id, XX, in catalog_id, XXXXXXXXX'

I can't see any Issue / Policy violations for those products.

This is the Sample Request Payload

{     "messaging_product": "whatsapp",     "recipient_type": "individual",     "to": "XXXX",     "type": "interactive",     "interactive": {         "type": "product",         "body": {             "text": "Hello 111111"         },         "footer": {             "text": "Hello1 1111111"         },         "action": {             "catalog_id": "XXXX",             "product_retailer_id": "XX"         }     }  } 

can you please help me to resolve this issue