export const metaAPI = HttpApi.make("MetaAPI")
.add(
HttpApiGroup.make("cloudAPI").add(
HttpApiEndpoint.post(
"sendTextMessage",
"/:whatsappPhoneNumberId/messages",
)
.setPath(
Schema.Struct({
whatsappPhoneNumberId: Schema.String,
}),
)
.setPayload(
Schema.Struct({
messaging_product: Schema.String,
recipient_type: Schema.String,
to: Schema.String,
type: Schema.String,
text: Schema.Struct({
preview_url: Schema.Boolean,
body: Schema.String,
}),
}),
),
),
)
.middleware(Authorization);
export const metaAPIClient = HttpApiClient.make(metaAPI, {
baseUrl: "https://graph.facebook.com/v21.0",
});
// my application code
Effect.gen(function* () {
// how can I insert the bearer token at this level?
const metaAPI = yield* metaAPIClient;
yield* metaAPI.cloudAPI
.sendTextMessage({
payload: {
messaging_product: "whatsapp",
recipient_type: "individual",
to: "+85295355691",
type: "text",
text: {
preview_url: true,
body: "heyy",
},
},
path: {
whatsappPhoneNumberId: whatsappPhoneNumberId,
},
})
}).pipe(Effect.provide(FetchHttpClient.layer), Effect.scoped);
export const metaAPI = HttpApi.make("MetaAPI")
.add(
HttpApiGroup.make("cloudAPI").add(
HttpApiEndpoint.post(
"sendTextMessage",
"/:whatsappPhoneNumberId/messages",
)
.setPath(
Schema.Struct({
whatsappPhoneNumberId: Schema.String,
}),
)
.setPayload(
Schema.Struct({
messaging_product: Schema.String,
recipient_type: Schema.String,
to: Schema.String,
type: Schema.String,
text: Schema.Struct({
preview_url: Schema.Boolean,
body: Schema.String,
}),
}),
),
),
)
.middleware(Authorization);
export const metaAPIClient = HttpApiClient.make(metaAPI, {
baseUrl: "https://graph.facebook.com/v21.0",
});
// my application code
Effect.gen(function* () {
// how can I insert the bearer token at this level?
const metaAPI = yield* metaAPIClient;
yield* metaAPI.cloudAPI
.sendTextMessage({
payload: {
messaging_product: "whatsapp",
recipient_type: "individual",
to: "+85295355691",
type: "text",
text: {
preview_url: true,
body: "heyy",
},
},
path: {
whatsappPhoneNumberId: whatsappPhoneNumberId,
},
})
}).pipe(Effect.provide(FetchHttpClient.layer), Effect.scoped);