in gen2 you can pass the secret in a similar way:
export const myCallback = onMessagePublished( { topic: "my-topic", secrets: [mySecret], }, () => { // your code goes here });