Closed spadillez closed 1 year ago
Forget to mencion using .netcore
@spadillez Hi, on my side I have no issue with the invalid request URI. Have you initialized the WhatsApp client in your controller class with dependency injection?
Yes
public WhatsappController(
TipoSolicitacaoService tipoSolicitacaoService,
UrgenciaSolicitacaoService urgenciaSolicitacaoService,
SolicitacaoUsuarioService solicitacaoUsuarioService,
UsuarioServico usuarioService,
IWhatsAppBusinessClient whatsAppBusinessClient)
{
_tipoSolicitacaoService = tipoSolicitacaoService;
_urgenciaSolicitacaoService = urgenciaSolicitacaoService;
_solicitacaoUsuarioService = solicitacaoUsuarioService;
_usuarioService = usuarioService;
_whatsAppBusinessClient = whatsAppBusinessClient;
}
You can send me a sample repo without the credentials so I can have a look what is happening with the request URI on your end.
Yes, i have find a way to get it work, using the legacy injection
`WhatsAppBusinessCloudApiConfig whatsAppConfig = new WhatsAppBusinessCloudApiConfig(); whatsAppConfig.WhatsAppBusinessPhoneNumberId = configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessPhoneNumberId"]; whatsAppConfig.WhatsAppBusinessAccountId = configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessAccountId"]; whatsAppConfig.WhatsAppBusinessId = configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessId"]; whatsAppConfig.AccessToken = configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["AccessToken"];
var httpClient = new HttpClient();
httpClient.BaseAddress = WhatsAppBusinessRequestEndpoint.BaseAddress;
//create Mpesa API client instance
_whatsAppBusinessClient = new WhatsAppBusinessClient(httpClient, whatsAppConfig);`
Tried to find why the httpclient got without the base url when using the DInjection but without success i will make a sample for you. But atleast it worked for now
Alright. I will investigate further the NET 6 builder for httpclient why it is not setting up the base url.
{"An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."}
Startup.CS
WhatsAppBusinessCloudApiConfig whatsAppConfig = new WhatsAppBusinessCloudApiConfig(); whatsAppConfig.WhatsAppBusinessPhoneNumberId = Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessPhoneNumberId"]; whatsAppConfig.WhatsAppBusinessAccountId = Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessAccountId"]; whatsAppConfig.WhatsAppBusinessId = Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessId"]; whatsAppConfig.AccessToken = Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["AccessToken"]; services.AddWhatsAppBusinessCloudApiService(whatsAppConfig);
Controller