-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Feature: Add WhatsApp with Vonage for PHP #206
Comments
I'm interested in working on this issue, can i be assigned pls? |
Hi @SoNiC-HeRE, I've assigned this issue to you! Thanks your interest in contributing to Appwrite! Happy Hacktoberfest 🎃 Notes:
|
Thank you; I'll keep the notes in mind. |
Progress:
To do:
|
I would like to work on this issue |
Hi, we are assigning issues on a first-come, first-serve basis, if @SoNiC-HeRE decides to drop off, we will assign it to you. |
I'm not sure what potentially am i doing wrong here since I'm getting no errors while deploying the page and when i try to send message (from a whitelisted and approved number) to the sandbox account i get no response |
Do you see anything helpful in the execution logs? Is Vonage calling your function? |
Ah,yes I tried logging as well, in the execution tab my Further I tried using Should i open a draft pr for this? |
I've updated the code as <?php
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/utils.php');
use \Firebase\JWT\JWT;
use GuzzleHttp\Client;
return function ($context) {
$context->log('Authentication');
throw_if_missing($_ENV, [
'VONAGE_API_KEY',
'VONAGE_API_SECRET',
'VONAGE_API_SIGNATURE_SECRET',
'VONAGE_WHATSAPP_NUMBER',
]);
if ($context->req->method === 'GET') {
return $context->res->send(get_static_file('index.html'), 200, [
'Content-Type' => 'text/html; charset=utf-8',
]);
}
$body = $context->req->body;
$headers = $context->req->headers;
$token = (isset($headers["Authorization"])) ? explode(" ", $headers["Authorization"])[1] : "";
try {
$decoded = JWT::decode($token, $_ENV['VONAGE_API_SIGNATURE_SECRET'], ['HS256']);
$context->log($decoded);
} catch (Exception $e) {
return $context->res->json([
'ok'=> false,
'error'=> $e->getMessage(),
]);
}
if (hash('sha256', $context->req->bodyRaw) !== $decoded['payload_hash']) {
return $context->res->json([
'ok' => false,
'error' => 'Payload hash mismatch'
]);
}
try {
throwIfMissing($context->req->body, ['from', 'text']);
} catch (Exception $e) {
return $context->res->json(["ok" => false, "error" => $e->getMessage()], 400);
}
$vonageApiKey = $_ENV['VONAGE_API_KEY'];
$vonageAccountSecret = $_ENV['VONAGE_API_SECRET'];
$basicAuthToken = base64_encode("$vonageApiKey:$vonageAccountSecret");
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Basic ' . $basicAuthToken,
];
$data = [
'from' => $_ENV['VONAGE_WHATSAPP_NUMBER'],
'to' => $context->req->body['from'],
'message-type' => 'text',
'text' => 'Hi there! You sent me: ' . $context->req->body['text'],
'channel' => 'whatsapp',
];
$client = new Client();
$url = "https://messages-sandbox.nexmo.com/v1/messages";
try {
$response = $client->post($url, [
"headers" => $headers,
"json" => $data,
]);
if ($response->getStatusCode() === 200) {
$result = json_decode($response->getBody(), true);
return $context->res->json(["ok" => true]);
} else {
$context->error("Error: " . $response->getBody());
return $context->res->json(["ok" => false, "error" => "Internal server error"], 500);
}
} catch (Exception $e) {
$context->error("Error: " . $e->getMessage());
return $context->res->json(["ok" => false, "error" => "Internal server error"], 500);
}
} In the executions tab my Issue Resolved ✅ |
Appwrite Functions allow you to extend and customize your Appwrite server functionality by executing your custom code. 🤩 You can learn more at our official Appwrite Functions docs.
Your task is to implement the WhatsApp with Vonage function in PHP. You can look at the existing Appwrite Functions Templates in another coding language.
Your function should behave and be implemented similarly to existing WhatsApp with Vonage Node.js template.
Tasks summary:
feat-implement-whatsapp-with-vonage-php
php/whatsapp-with-vonage/
.README.md
explaining what the function does, how to use it, and customize it. Here is an example.If you need any help, contact us on our Discord server.
Are you ready to work on this issue? 🤔 Let us know, and we will assign it to you 😊
Happy coding!
The text was updated successfully, but these errors were encountered: