20 lines
667 B
TypeScript
20 lines
667 B
TypeScript
import { httpRequest } from '~/helpers/http/axios'
|
|
import logger from '~/plugins/logger'
|
|
|
|
export async function sendCommandToThirdParty(topicData: string, payload: string): Promise<void> {
|
|
try {
|
|
const response = await httpRequest({
|
|
method: 'POST',
|
|
url: '/command',
|
|
body: {
|
|
topic: topicData,
|
|
payload,
|
|
},
|
|
})
|
|
logger.info({ msg: 'Third-party command sent successfully', topic: topicData, status: response.status })
|
|
} catch (error) {
|
|
logger.error({ msg: 'Failed to send command to third-party service', topic: topicData, error: (error as Error).message })
|
|
throw new Error('third_party_command_failed')
|
|
}
|
|
}
|