https://discord.gg/botpress logo
Error in set State data using integration
# šŸ¤help
s
I am using custom integration. Where I have defined below state ------- state definition start -------------- import { z, IntegrationDefinitionProps } from '@botpress/sdk'; const userData = { type: 'conversation' as const, schema: z.object({ userName: z.string(), emailAddress: z.string(), token: z.string(), customerID: z.number(), offsetMinute: z.number(), }), }; export const states = { userData, } satisfies IntegrationDefinitionProps['states']; ------- state definition end -------------- I am using below code to set state data ---------- Set State Start -------------- const setUserData = async (payload: bp.states.States['userData'], client: IntegrationSpecificClient, conversationId: string) => { await client.setState({ name: 'userData', type: 'conversation', payload: { userName: payload.userName, emailAddress: payload.emailAddress, token: payload.token, customerID: payload.customerID, offsetMinute: payload.offsetMinute, }, id: conversationId, }); }; ---------- Set State End ------------------- I am getting below error while setting state data Error in Handler - ve [Error]: Conversation "conv_01K8......SSFP6733F3" is not owned by integration "" ... at async handleHTTPEvent (/var/task/index.js:20:13710) { isApiError: true, code: 403, description: "The requested action can't be peform by this resource.", type: 'Forbidden', error: undefined, id: 'c2db9e......2382711d' } It's very strange that initially, when I have implemented this function, it was working fine. our team has tested it multiple time. But after some time, when we have tested it again (There were no code change), it's not working Please let me know, what can be the possible solution? I am happy to share more details if required. Thanks in Advance!
w
you can check the x-integrationd-id you're using in your requests
and also check your conversations to see if they're actually owned by that integration
each conversation can only be owned by a single integration (or channel) and if you try interacting with it using any other x-integration-id you'll get that error
s
Yes, @wide-umbrella-5226 , that's correct. The *conversationId *is from the *Chat *integration, and we’re using it in our custom integration to set/get state data. Let me explain our requirement: 1 - We have some user data (like username and emailAddress) available in the mobile application. 2 - Initially, when new conversation starts, we want to set that data into the conversation’s state. 3 - When a new workflow starts, we want to retrieve that state data and store it into workflow variables. 4 - Those workflow variables are then passed to our custom integration. Can you please guide me on how to achieve steps #2 and #3?
w
well since you're already passing a lot of stuff through the chat api you can just pass the variables together in the interaction payload
your "new conversation starts" is probably your backend sending an event to the chat api
so if you include "userName": "John" in your payload, you can access it in your workflow
like doing "user.name = {{event.payload.userName}}" in an execute code block
s
Thank you — @wide-umbrella-5226 that solution worked. Could you please share the link to the official documentation for this approach? I’d like to review it in more detail. Additionally, I’m curious about what might have changed on the Botpress side. Our previous implementation had been working reliably for quite some time, and the team had tested it thoroughly without any issues. Do you know what specific update or modification could have caused it to stop working recently?
w
since you're using the Chat API, these could help: https://www.botpress.com/docs/api-reference/chat-api/openapi/createUser https://www.botpress.com/docs/api-reference/chat-api/openapi/createConversation https://www.botpress.com/docs/api-reference/chat-api/openapi/createMessage about what has changed - i'm not entirely sure. i don't personally use the chat api (or really recommend it), i prefer using the [Messaging API](https://www.botpress.com/integrations/messaging)
3 Views