Hi all, I need some help for my study.
# 🤝help
g
Currently I am trying to export my conversations for analyses. I can see the conversation data in terms of integration, creation date, etc. However, I am unable to access the conversation contect (ie., the user- and chatbot- responses). How can I access the content? Preferably in Javascript or Python, and 1) Without using Botpress Client library, and 2) using Client library without npm. As a social scientist I am a coding noob and i am asking the question on behalf of my collegue that has some coding experience. All help is appreciated!
l
@gray-napkin-43750 , here you go. Python, using only "requests" package:
Copy code
def retrieve_messages(bot_id, conversation_id):

    botpress_personal_access_token = <your personal access token. might be worth having it as an environment variable>

    botpress_bot_id = bot_id


    headers = {
        'Authorization': f'Bearer {botpress_personal_access_token}',
        'x-bot-id': botpress_bot_id,
    }

    all_messages = []

    api_url = f'https://api.botpress.cloud/v1/chat/messages?conversationId={conversation_id}'

    response = requests.get(api_url, headers=headers)

    if response.status_code == 200:
        all_messages.extend(response.json()['messages'])
        return all_messages
    else:
          print(f'Error: {response.status_code}')
        return None
The reason you're not getting the messages is because conversation objects don't include those (https://botpress.com/docs/api-documentation/#get-conversation), and you have to make a separate call at /v1/chat/messages to get the messages associated with a given conversation.
2 Views