chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { createChannelWrapper } from '@botpress/common'
|
||||
import { TrelloClient } from 'src/trello-api/trello-client'
|
||||
import * as bp from '.botpress'
|
||||
|
||||
export const wrapChannel = createChannelWrapper<bp.IntegrationProps>()({
|
||||
toolFactories: {
|
||||
trelloClient: ({ ctx }) => new TrelloClient({ ctx }),
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
import { CardCommentPublisher } from './publishers/card-comments'
|
||||
import * as bp from '.botpress'
|
||||
|
||||
export const channels = {
|
||||
cardComments: {
|
||||
messages: {
|
||||
text: CardCommentPublisher.publishTextMessage,
|
||||
},
|
||||
},
|
||||
} as const satisfies bp.IntegrationProps['channels']
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as sdk from '@botpress/sdk'
|
||||
import { wrapChannel } from '../channel-wrapper'
|
||||
|
||||
export namespace CardCommentPublisher {
|
||||
export const publishTextMessage = wrapChannel(
|
||||
{ channelName: 'cardComments', messageType: 'text' },
|
||||
async ({ trelloClient, conversation, ack, payload, client }) => {
|
||||
if (!conversation.tags.cardId) {
|
||||
throw new sdk.RuntimeError('Card id must be set')
|
||||
}
|
||||
|
||||
const commentId = await trelloClient.addCardComment({
|
||||
cardId: conversation.tags.cardId,
|
||||
commentBody: payload.text,
|
||||
})
|
||||
|
||||
await client.updateConversation({
|
||||
id: conversation.id,
|
||||
tags: {
|
||||
lastCommentId: commentId,
|
||||
},
|
||||
})
|
||||
|
||||
await ack({ tags: { commentId } })
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user