gentle-shampoo-88367
08/31/2023, 7:44 AMInvoke Error {"message":"Request failed with status code 401","name":"AxiosError","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","x-bp-messaging-client-id":"0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc","x-bp-messaging-client-token":"0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc","User-Agent":"axios/0.27.2","Content-Length":270},"baseURL":"https://messaging.botpress.cloud/api/v1","method":"post","url":"/messages","data":"{\"conversationId\":\"d42854a6-c222-4871-928b-590aecb14521\",\"authorId\":\"0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc\",\"payload\":{\"type\":\"trigger\",\"trigger\":{\"type\":\"custom-event\",\"event\":{\"link\":\"https://studio.botpress.cloud/0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc/flows/wf-main\"}}}}"},"code":"ERR_BAD_REQUEST","status":401}
acceptable-kangaroo-64719
08/31/2023, 10:37 AMgentle-shampoo-88367
08/31/2023, 1:08 PMgentle-shampoo-88367
08/31/2023, 1:32 PMimport type { IntegrationProps } from '.botpress'
import { MessagingClient } from '@botpress/messaging-client'
export const sendEvent: IntegrationProps['actions']['sendEvent'] = async (props) => {
return sendTrigger(props)({
type: 'custom-event',
event: JSON.parse(`{"link":"${props.input.event}"}`),
})
}
// Invoke Error {"id":"err_1693445645238x4ECD7A08","code":400,"type":"ReferenceNotFound","message":"State \"webchat\" of type \"integration\" isn't defined for the integration \"fc99948c-ba97-4f1c-a1ce-ea0c0708afa9\""}
const sendTrigger = ({ client, input, ctx }) => async (trigger: any) => {
const { conversation } = await client.getConversation({ id: input.conversationId })
await send({
message: {
type: 'trigger',
trigger,
},
ctx: ctx,
conversation:conversation,
client:client,
})
return {}
}
const send = async (params: { message: any, ctx: any, conversation: any, client: any }) => {
const { message, ctx, client, conversation } = params
const { configuration, integrationId } = ctx
const { messagingUrl, botIda, clientToken } = configuration
const botId = "0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc"
// const messagingClient = await getMessagingClient(ctx, client)
const messagingClient = new MessagingClient({
url: "https://messaging.botpress.cloud",
clientId: "0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc",
clientToken: "0e46922c-1f42-43cc-8bb0-cad4a3d3d4cc",
// webhookToken,
})
const conversationId = getTag(conversation.tags, 'id')
if (!conversationId) {
throw new Error('No conversation id')
}
console.log(botId);
await messagingClient.createMessage(conversationId, botId, message)
}
const getTag = (tags: Record<string, string>, name: string) => {
return tags[`webchat:${name}`]
}
acceptable-kangaroo-64719
08/31/2023, 2:50 PMgentle-shampoo-88367
08/31/2023, 4:35 PMgentle-shampoo-88367
08/31/2023, 4:35 PMacceptable-kangaroo-64719
08/31/2023, 5:18 PMcolossal-egg-20510
08/31/2023, 6:22 PMmessagingClient
to send a message to a conversation that was created by the webchat integration will be hard. There is a webhookToken
necessary to do those calls which is created by the webchat integration and isn't available publicly.colossal-egg-20510
08/31/2023, 6:24 PMgentle-shampoo-88367
08/31/2023, 6:26 PMgentle-shampoo-88367
08/31/2023, 6:27 PMgentle-shampoo-88367
08/31/2023, 6:27 PMcolossal-egg-20510
08/31/2023, 6:29 PMSend Custom Event
action of the webchat integration ? It looks like it is pretty similar to what you're trying to achieve.colossal-egg-20510
08/31/2023, 7:12 PMSend Custom Event
doesn't fit your needs I can do a one time exception to provide you the Webhook token of your bot. You can DM me the bot Id.gentle-shampoo-88367
08/31/2023, 7:13 PMgentle-shampoo-88367
08/31/2023, 7:16 PMgentle-shampoo-88367
08/31/2023, 8:40 PMcrooked-van-25152
08/31/2023, 9:10 PMgentle-shampoo-88367
08/31/2023, 9:20 PMcolossal-egg-20510
08/31/2023, 9:53 PMgentle-shampoo-88367
08/31/2023, 9:54 PM