• Josef Aslan
  • NEWBIE
  • 25 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
The Leads in our Org have 4 possible values for the "Industry" field. We would like to create one custom item on the Navigation Bar for every value in the "Industry" field, so that if we click on an item, it will show us a filtered list of Leads only with that specific field value. Is this somehow possible?
I'm set-up to mass convert leads into contacts via APEX code. The problem that I encounter is that the value of the leads "Company" field has to be transmitted into the new contacts object. As I figured out, it is not possible to map standard lead fields into custom contacts fields, and by default, the "Company" field does not get transmitted into the contacts object. This is necessary, so that in the future we have the option to filter contacts based on their "Company" value.
So I created a Apex-class that acts as a webhook to get logs of messages from our Whatsapp API and saves certain parameters in a custom object. When I send a message to our business account, the debug log shows that the webhook works and a custom object is created. However, this record is nowhere to find and it seems like no record is being created. This is the webhook class:
 
@RestResource(urlMapping='/some_url')
global without sharing class WhatsAppWebhook {
    
    private static Final String SIGNATURE_VALID_MESSAGE     = 'Signature Verified';
    private static Final String SIGNATURE_NOT_VALID_MESSAGE = 'Signature could not be verified';
    
    @HttpGet // GET
    global static void doGet() {
        RestResponse response = RestContext.response;
        RestRequest request = RestContext.request;
        if(request.params.get('hub.verify_token') == 'token'){
            response.responseBody = Blob.valueOf( request.params.get('hub.challenge') );
        }
    }
    
    @HttpPost // POST
    global static void doPost() {
        
        RestResponse response = RestContext.response;
        response.addHeader('Content-type','application/json');
        String responseString = RestContext.request.requestBody.toString();
        Map<String, String> headers = RestContext.request.headers;
        String responseValid = validateWhatsAppSignature(RestContext.request, responseString);
        
        if(responseValid == SIGNATURE_VALID_MESSAGE || system.test.isRunningTest()){
            System.debug(System.LoggingLevel.DEBUG, ' Headers Response From WhatsApp \n  '+ JSON.serialize(headers) );
            System.debug(System.LoggingLevel.DEBUG, ' Response From WhatsApp \n  '+ responseString);
            String finalResponseString = responseString.replace('type', 'typex');
            WhatsAppMessage parentMessage = (WhatsAppMessage)JSON.deserialize( finalResponseString, WhatsAppMessage.class);
            List<WhatsAppMessage.entry> messageEntries = parentMessage.entry;
            if(messageEntries != null && messageEntries.size() > 0){
                WhatsAppMessage.entry entryMessage = messageEntries.get(0);
                List<WhatsAppMessage.changes> changeMessages = entryMessage.changes;
                if(changeMessages != null && changeMessages.size() > 0){
                    WhatsAppMessage.changes changeMessage = changeMessages.get(0);
                    List<WhatsAppMessage.contacts> contactList = changeMessage.value.contacts;
                    List<WhatsAppMessage.messages> messageList = changeMessage.value.messages;
                    WhatsAppMessage.metadata metadata = changeMessage.value.metadata;
                    /* Create record into Salesforce */
                    WhatsAppChat__c salesforceMessage = new WhatsAppChat__c();
                    salesforceMessage.Business_Telefonnummer__c = metadata != null ? metadata.display_phone_number : null;
                    
                    if(contactList != null && contactList.size() > 0){
                        WhatsAppMessage.contacts contact = contactList.get(0);
                        salesforceMessage.Klient_Nummer__c = contact.wa_id;
                        salesforceMessage.Klient_Name__c = contact.profile.name;
                    }
                    
                    if(messageList != null && messageList.size() > 0){
                        /* Simple Message */
                        WhatsAppMessage.messages message = messageList.get(0);
                        salesforceMessage.Nachrichten_ID__c = message.id;
                        salesforceMessage.Nachrichtentyp__c = message.typex;
                        salesforceMessage.Nachrichten_Zeitstempel__c = System.now();
                        salesforceMessage.Nachricht__c = message.text != null? message.text.body : null;
                        
                        /* If message is reaction */
                        salesforceMessage.Reaktion__c = message.reaction != null ? message.reaction.emoji : null;
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.reaction != null ? message.reaction.message_id : null;
                        
                        /* If message is Image */
                        salesforceMessage.Bild_ID__c = message.image != null ? message.image.id : null;
                        salesforceMessage.Bildtyp__c = message.image != null ? message.image.mime_type : null;
                        salesforceMessage.Bild_sha256__c = message.image != null ? message.image.sha256 : null;
                        
                        /* If message is Video */
                        salesforceMessage.Video_ID__c = message.video != null ? message.video.id : null;
                        salesforceMessage.Videotyp__c = message.video != null ? message.video.mime_type : null;
                        salesforceMessage.Video_SHA256__c = message.video != null ? message.video.sha256 : null;
                        
                        /* If the message is reply to another message */
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.context != null ? message.context.id : null;
                        
                        upsert salesforceMessage Nachrichten_ID__c;
                    }
                    
                }
            }
        }else{
            response.responseBody = Blob.valueOf('{success:false, event:"Unknown","message:"'+responseValid+'"}');
            response.statusCode = 401;
            return;
        }
        
        response.statusCode = 200;
        response.responseBody = Blob.valueOf('{success:true, event:"success"}');
    }
    
    private static String validateWhatsAppSignature(RestRequest request, String responseString) {
        // Validate Stripe signature Start 
        Map<String, String> headers = request.headers;
        
        String whatsAppSignature = headers.get('X-Hub-Signature-256');
        
        String whatsAppPayload = RestContext.request.requestBody.toString();
        
        // Verify the signature using 'hmacSHA256'. I have the Webhook key stored in a Custom Label
        String whatsAppSecret = System.Label.FBAppToken; // Facebook Application Secret Key
        Blob signedPayload = Crypto.generateMac('hmacSHA256', Blob.valueOf(whatsAppPayload), Blob.valueOf( whatsAppSecret ));
        
        String encodedPayload = 'sha256='+EncodingUtil.convertToHex(signedPayload);
        // Return status code based on whether signed payload matches or not
        
        String response = (encodedPayload == whatsAppSignature)? SIGNATURE_VALID_MESSAGE : SIGNATURE_NOT_VALID_MESSAGE;
        return response;
        // Validate Stripe signature End 
    }
}
This is the class that's also being referred to in above class:
 
public class WhatsAppMessage {
    
    public entry[] entry;
    public class entry {
        public String id;	
        public changes[] changes;
    }
    public class changes {
        public value value;
        public String field;	
    }
    public class value {
        public String messaging_product;	
        public metadata metadata;
        public contacts[] contacts;
        public messages[] messages;
    }
    public class metadata {
        public String display_phone_number;	
        public String phone_number_id;	
    }
    public class contacts {
        public profile profile;
        public String wa_id;	
    }
    public class profile {
        public String name;	
    }
    public class messages {
        public context context;
        public String fromx;	
        public String id;	
        public String timestamp;	
        public text text;
        public String typex;	
        public reaction reaction;
        public image image;
        public image video;
    }
    public class context {
        public String fromx;	
        public String id;	
    }
    public class text {
        public String body;	
    }
    public class reaction{
        public String emoji;
        public String message_id;
    }
    public class image{
        public String mime_type;
        public String id;
        public String sha256;
    }
}

And this snipped of the debug-log shows that the object WhatsAppChat__c is being created:

User-added image
Any suggestion on how to solve this is greatly appreciated.
 
So really struggling with composing a test class for a apex webhook class that saves different parameters after making an api call to the whatsapp cloud api. I know about the basics of writing tests, but don't have a clue on how to test certain lines of code that require a given set of data to work with. This is my webhook class:
@RestResource(urlMapping='/whatsapp/webhooks/v1/*')
global without sharing class WhatsAppWebhook {
    
    private static Final String SIGNATURE_VALID_MESSAGE     = 'Signature Verified';
    private static Final String SIGNATURE_NOT_VALID_MESSAGE = 'Signature could not be verified';
    
    @HttpGet // GET
    global static void doGet() {
        RestResponse response = RestContext.response;
        RestRequest request = RestContext.request;
        if(request.params.get('hub.verify_token') == 'TOKEN_HERE'){
            response.responseBody = Blob.valueOf( request.params.get('hub.challenge') );
        }
    }
    
    @HttpPost // POST
    global static void doPost() {
        
        RestResponse response = RestContext.response;
        response.addHeader('Content-type','application/json');
        String responseString = RestContext.request.requestBody.toString();
        Map<String, String> headers = RestContext.request.headers;
        String responseValid = validateWhatsAppSignature(RestContext.request, responseString);
        
        if(responseValid == SIGNATURE_VALID_MESSAGE){
            System.debug(System.LoggingLevel.DEBUG, ' Headers Response From WhatsApp \n  '+ JSON.serialize(headers) );
            System.debug(System.LoggingLevel.DEBUG, ' Response From WhatsApp \n  '+ responseString);
            String finalResponseString = responseString.replace('type', 'typex');
            WhatsAppMessage parentMessage = (WhatsAppMessage)JSON.deserialize( finalResponseString, WhatsAppMessage.class);
            List<WhatsAppMessage.entry> messageEntries = parentMessage.entry;
            if(messageEntries != null && messageEntries.size() > 0){
                WhatsAppMessage.entry entryMessage = messageEntries.get(0);
                List<WhatsAppMessage.changes> changeMessages = entryMessage.changes;
                if(changeMessages != null && changeMessages.size() > 0){
                    WhatsAppMessage.changes changeMessage = changeMessages.get(0);
                    List<WhatsAppMessage.contacts> contactList = changeMessage.value.contacts;
                    List<WhatsAppMessage.messages> messageList = changeMessage.value.messages;
                    WhatsAppMessage.metadata metadata = changeMessage.value.metadata;
                    /* Create record into Salesforce */
                    WhatsAppChat__c salesforceMessage = new WhatsAppChat__c();
                    salesforceMessage.Business_Telefonnummer__c = metadata != null ? metadata.display_phone_number : null;
                    
                    if(contactList != null && contactList.size() > 0){
                        WhatsAppMessage.contacts contact = contactList.get(0);
                        salesforceMessage.Klient_Nummer__c = contact.wa_id;
                        salesforceMessage.Klient_Name__c = contact.profile.name;
                    }
                    
                    if(messageList != null && messageList.size() > 0){
                        /* Simple Message */
                        WhatsAppMessage.messages message = messageList.get(0);
                        salesforceMessage.Nachrichten_ID__c = message.id;
                        salesforceMessage.Nachrichtentyp__c = message.typex;
                        salesforceMessage.Nachrichten_Zeitstempel__c = System.now();
                        salesforceMessage.Nachricht__c = message.text != null? message.text.body : null;
                        
                        /* If message is reaction */
                        salesforceMessage.Reaktion__c = message.reaction != null ? message.reaction.emoji : null;
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.reaction != null ? message.reaction.message_id : null;
                        
                        /* If message is Image */
                        salesforceMessage.Bild_ID__c = message.image != null ? message.image.id : null;
                        salesforceMessage.Bildtyp__c = message.image != null ? message.image.mime_type : null;
                        salesforceMessage.Bild_sha256__c = message.image != null ? message.image.sha256 : null;
                        
                        /* If message is Video */
                        salesforceMessage.Video_ID__c = message.video != null ? message.video.id : null;
                        salesforceMessage.Videotyp__c = message.video != null ? message.video.mime_type : null;
                        salesforceMessage.Video_SHA256__c = message.video != null ? message.video.sha256 : null;
                        
                        /* If the message is reply to another message */
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.context != null ? message.context.id : null;
                        
                        upsert salesforceMessage Nachrichten_ID__c;
                    }
                    
                }
            }
        }else{
            response.responseBody = Blob.valueOf('{success:false, event:"Unknown","message:"'+responseValid+'"}');
            response.statusCode = 401;
            return;
        }
        
        response.statusCode = 200;
        response.responseBody = Blob.valueOf('{success:true, event:"success"}');
    }
    
    private static String validateWhatsAppSignature(RestRequest request, String responseString) {
        // Validate Stripe signature Start 
        Map<String, String> headers = request.headers;
        
        String whatsAppSignature = headers.get('X-Hub-Signature-256');
        
        String whatsAppPayload = RestContext.request.requestBody.toString();
        
        // Verify the signature using 'hmacSHA256'. I have the Webhook key stored in a Custom Label
        String whatsAppSecret = System.Label.FBAppToken; // Facebook Application Secret Key
        Blob signedPayload = Crypto.generateMac('hmacSHA256', Blob.valueOf(whatsAppPayload), Blob.valueOf( whatsAppSecret ));
        
        String encodedPayload = 'sha256='+EncodingUtil.convertToHex(signedPayload);
        // Return status code based on whether signed payload matches or not
        
        String response = (encodedPayload == whatsAppSignature)? SIGNATURE_VALID_MESSAGE : SIGNATURE_NOT_VALID_MESSAGE;
        return response;
        // Validate Stripe signature End 
    }
}

And below is the test class, which only covers 40% of the code:
 
@IsTest
private class WhatsAppWebhookTest {
    @IsTest
    static void testDoGet() {
        RestRequest request = new RestRequest();
        RestResponse response = new RestResponse();
        request.requestURI = '/whatsapp/webhooks/v1/';
        request.addParameter('hub.verify_token', 'whatsapp');
        request.addParameter('hub.challenge', 'test');
        RestContext.request = request;
        RestContext.response = response;
        
        WhatsAppWebhook.doGet();
        
        System.assertEquals(200, response.statusCode);
        System.assertEquals('test', response.responseBody.toString());
    }
    
    @IsTest
    static void testDoPost_ValidSignature() {
        RestRequest request = new RestRequest();
        RestResponse response = new RestResponse();
        request.requestURI = '/whatsapp/webhooks/v1/';
        request.headers.put('X-Hub-Signature-256', 'sha256=valid_signature');
        request.requestBody = Blob.valueOf('{"type": "message"}');
        RestContext.request = request;
        RestContext.response = response;
        
        
        WhatsAppWebhook.doPost();
        
        System.assertEquals(200, response.statusCode);
        System.assertEquals('{"success":true, "event":"success"}', response.responseBody.toString());
        System.assertEquals('hey', salesforceMessage.Nachricht__c);
    }
    
    @IsTest
    static void testDoPost_InvalidSignature() {
        RestRequest request = new RestRequest();
        RestResponse response = new RestResponse();
        request.requestURI = '/whatsapp/webhooks/v1/';
        request.headers.put('X-Hub-Signature-256', 'sha256=invalid_signature');
        request.requestBody = Blob.valueOf('{"type": "message"}');
        RestContext.request = request;
        RestContext.response = response;
        
        
        WhatsAppWebhook.doPost();
        
        System.assertEquals(401, response.statusCode);
        System.assertEquals('{success:false, event:"Unknown","message:"Signature could not be verified"}', response.responseBody.toString());
    }
    
    
    @IsTest
    static void testDoPost_NoMessageEntries() {
        RestRequest request = new RestRequest();
        RestResponse response = new RestResponse();
        request.requestURI = '/whatsapp/webhooks/v1/';
        request.headers.put('X-Hub-Signature-256', 'sha256=valid_signature');
        request.requestBody = Blob.valueOf('{"type": "no_entries"}');
        RestContext.request = request;
        RestContext.response = response;
        
        
        WhatsAppWebhook.doPost();
        
        System.assertEquals(200, response.statusCode);
        System.assertEquals('{"success":true, "event":"success"}', response.responseBody.toString());
    }
}

What's the right way to tackle this issue?
Hello, I'm pretty new to developing on Salesforce and currently try my best to successfully integrate a whatsapp integration into our production site. I've written an apex class for webhooks to listen to whatsapp messages and successfully wrote a test class for this thanks to the help of a community member. Howver, after modifications I need more test methods since I don't reach 75% code coverage and i run into the same issues writing these. Here's the code:
 
@RestResource(urlMapping='/whatsapp/webhooks/v1/*')
global without sharing class WhatsAppWebhook {
    
    private static Final String SIGNATURE_VALID_MESSAGE     = 'Signature Verified';
    private static Final String SIGNATURE_NOT_VALID_MESSAGE = 'Signature could not be verified';
    
    @HttpGet // GET
    global static void doGet() {
        RestResponse response = RestContext.response;
        RestRequest request = RestContext.request;
        if(request.params.get('hub.verify_token') == 'WHATSAPPTOKEN'){
            response.responseBody = Blob.valueOf( request.params.get('hub.challenge') );
        }
    }
    
    @HttpPost // POST
    global static void doPost() {
        
        RestResponse response = RestContext.response;
        response.addHeader('Content-type','application/json');
        String responseString = RestContext.request.requestBody.toString();
        Map<String, String> headers = RestContext.request.headers;
        String responseValid = validateWhatsAppSignature(RestContext.request, responseString);
        
        if(responseValid == SIGNATURE_VALID_MESSAGE){
            System.debug(System.LoggingLevel.DEBUG, ' Headers Response From WhatsApp \n  '+ JSON.serialize(headers) );
            System.debug(System.LoggingLevel.DEBUG, ' Response From WhatsApp \n  '+ responseString);
            String finalResponseString = responseString.replace('type', 'typex');
            WhatsAppMessage parentMessage = (WhatsAppMessage)JSON.deserialize( finalResponseString, WhatsAppMessage.class);
            List<WhatsAppMessage.entry> messageEntries = parentMessage.entry;
            if(messageEntries != null && messageEntries.size() > 0){
                WhatsAppMessage.entry entryMessage = messageEntries.get(0);
                List<WhatsAppMessage.changes> changeMessages = entryMessage.changes;
                if(changeMessages != null && changeMessages.size() > 0){
                    WhatsAppMessage.changes changeMessage = changeMessages.get(0);
                    List<WhatsAppMessage.contacts> contactList = changeMessage.value.contacts;
                    List<WhatsAppMessage.messages> messageList = changeMessage.value.messages;
                    WhatsAppMessage.metadata metadata = changeMessage.value.metadata;
                    /* Create record into Salesforce */
                    WhatsApp__c salesforceMessage = new WhatsApp__c();
                    salesforceMessage.Business_Telefonnummer__c = metadata != null ? metadata.display_phone_number : null;
                    
                    if(contactList != null && contactList.size() > 0){
                        WhatsAppMessage.contacts contact = contactList.get(0);
                        salesforceMessage.Klient_Nummer__c = contact.wa_id;
                        salesforceMessage.Klient_Name__c = contact.profile.name;
                    }
                    
                    if(messageList != null && messageList.size() > 0){
                        /* Simple Message */
                        WhatsAppMessage.messages message = messageList.get(0);
                        salesforceMessage.Nachrichten_ID__c = message.id;
                        salesforceMessage.Nachrichtentyp__c = message.typex;
                        salesforceMessage.Nachrichten_Zeitstempel__c = System.now();
                        salesforceMessage.Nachricht__c = message.text != null? message.text.body : null;
                        
                        /* If message is reaction */
                        salesforceMessage.Reaktion__c = message.reaction != null ? message.reaction.emoji : null;
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.reaction != null ? message.reaction.message_id : null;
                        
                        /* If message is Image */
                        salesforceMessage.Bild_ID__c = message.image != null ? message.image.id : null;
                        salesforceMessage.Bildtyp__c = message.image != null ? message.image.mime_type : null;
                        salesforceMessage.Bild_sha256__c = message.image != null ? message.image.sha256 : null;
                        
                        /* If message is Video */
                        salesforceMessage.Video_ID__c = message.video != null ? message.video.id : null;
                        salesforceMessage.Videotyp__c = message.video != null ? message.video.mime_type : null;
                        salesforceMessage.Video_SHA256__c = message.video != null ? message.video.sha256 : null;
                        
                        /* If the message is reply to another message */
                        salesforceMessage.Kontext_Nachrichten_ID__c = message.context != null ? message.context.id : null;
                        
                        upsert salesforceMessage Nachrichten_ID__c;
                    }
                    
                }
            }
        }else{
            response.responseBody = Blob.valueOf('{success:false, event:"Unknown","message:"'+responseValid+'"}');
            response.statusCode = 401;
            return;
        }
        
        response.statusCode = 200;
        response.responseBody = Blob.valueOf('{success:true, event:"success"}');
    }
    
    private static String validateWhatsAppSignature(RestRequest request, String responseString) {
        // Validate Stripe signature Start 
        Map<String, String> headers = request.headers;
        
        String whatsAppSignature = headers.get('X-Hub-Signature-256');
        
        String whatsAppPayload = RestContext.request.requestBody.toString();
        
        // Verify the signature using 'hmacSHA256'. I have the Webhook key stored in a Custom Label
        String whatsAppSecret = System.Label.FBAppToken; // Facebook Application Secret Key
        Blob signedPayload = Crypto.generateMac('hmacSHA256', Blob.valueOf(whatsAppPayload), Blob.valueOf( whatsAppSecret ));
        
        String encodedPayload = 'sha256='+EncodingUtil.convertToHex(signedPayload);
        // Return status code based on whether signed payload matches or not
        
        String response = (encodedPayload == whatsAppSignature)? SIGNATURE_VALID_MESSAGE : SIGNATURE_NOT_VALID_MESSAGE;
        return response;
        // Validate Stripe signature End 
    }
}

Any help is very much appreciated!
Hello, I'm pretty new to developing on Salesforce and currently try my best to successfully integrate a whatsapp integration into our production site. I've written an apex class for webhooks to listen to whatsapp messages, but am currently stuck at writing the test class for the code. I don't really know how to set-up test methods for http post and get requests. This is the apex class I've written alongside a tutorial video:
 
@RestResource(urlMapping='/whatsapp/webhooks/v1/*')
global class WhatsAppWebhook {
    
    private static Final String SIGNATURE_VALID_MESSAGE     = 'Signature Verified';
    private static Final String SIGNATURE_NOT_VALID_MESSAGE = 'Signature could not be verified';
    
    @HttpGet // GET
    global static void doGet() {
        RestResponse response = RestContext.response;
        RestRequest request = RestContext.request;
        if(request.params.get('hub.verify_token') == 'WHATSAPPTOKEN'){
            response.responseBody = Blob.valueOf( request.params.get('hub.challenge') );
        }
    }
    
    @HttpPost // POST
    global static void doPost() {
        
        RestResponse response = RestContext.response;
        response.addHeader('Content-type','application/json');
        String responseString = RestContext.request.requestBody.toString();
        Map<String, String> headers = RestContext.request.headers;
        String responseValid = validateWhatsAppSignature(RestContext.request, responseString);
        
        if(responseValid == SIGNATURE_VALID_MESSAGE){
            System.debug(System.LoggingLevel.DEBUG, ' Headers Response From WhatsApp \n  '+ JSON.serialize(headers) );
            System.debug(System.LoggingLevel.DEBUG, ' Response From WhatsApp \n  '+ responseString);
        }else{
            response.responseBody = Blob.valueOf('{success:false, event:"Unknown","message:"'+responseValid+'"}');
            response.statusCode = 401;
            return;
        }
        
        response.statusCode = 200;
        response.responseBody = Blob.valueOf('{success:true, event:"success"}');
    }
    
    private static String validateWhatsAppSignature(RestRequest request, String responseString) {
        // Validate Stripe signature Start 
        Map<String, String> headers = request.headers;
        
        String whatsAppSignature = headers.get('X-Hub-Signature-256');
        
        String whatsAppPayload = RestContext.request.requestBody.toString();
        
        // Verify the signature using 'hmacSHA256'. I have the Webhook key stored in a Custom Label
        String whatsAppSecret = System.Label.WHATSAPPSECRET; // Facebook Application Secret Key
        Blob signedPayload = Crypto.generateMac('hmacSHA256', Blob.valueOf(whatsAppPayload), Blob.valueOf( whatsAppSecret ));
        
        String encodedPayload = 'sha256='+EncodingUtil.convertToHex(signedPayload);
        // Return status code based on whether signed payload matches or not
        
        String response = (encodedPayload == whatsAppSignature)? SIGNATURE_VALID_MESSAGE : SIGNATURE_NOT_VALID_MESSAGE;
        return response;
        // Validate Stripe signature End 
    }
}

I would appreciate any tips on how to tackle the issue.
I'm set-up to mass convert leads into contacts via APEX code. The problem that I encounter is that the value of the leads "Company" field has to be transmitted into the new contacts object. As I figured out, it is not possible to map standard lead fields into custom contacts fields, and by default, the "Company" field does not get transmitted into the contacts object. This is necessary, so that in the future we have the option to filter contacts based on their "Company" value.
Hello, I'm pretty new to developing on Salesforce and currently try my best to successfully integrate a whatsapp integration into our production site. I've written an apex class for webhooks to listen to whatsapp messages, but am currently stuck at writing the test class for the code. I don't really know how to set-up test methods for http post and get requests. This is the apex class I've written alongside a tutorial video:
 
@RestResource(urlMapping='/whatsapp/webhooks/v1/*')
global class WhatsAppWebhook {
    
    private static Final String SIGNATURE_VALID_MESSAGE     = 'Signature Verified';
    private static Final String SIGNATURE_NOT_VALID_MESSAGE = 'Signature could not be verified';
    
    @HttpGet // GET
    global static void doGet() {
        RestResponse response = RestContext.response;
        RestRequest request = RestContext.request;
        if(request.params.get('hub.verify_token') == 'WHATSAPPTOKEN'){
            response.responseBody = Blob.valueOf( request.params.get('hub.challenge') );
        }
    }
    
    @HttpPost // POST
    global static void doPost() {
        
        RestResponse response = RestContext.response;
        response.addHeader('Content-type','application/json');
        String responseString = RestContext.request.requestBody.toString();
        Map<String, String> headers = RestContext.request.headers;
        String responseValid = validateWhatsAppSignature(RestContext.request, responseString);
        
        if(responseValid == SIGNATURE_VALID_MESSAGE){
            System.debug(System.LoggingLevel.DEBUG, ' Headers Response From WhatsApp \n  '+ JSON.serialize(headers) );
            System.debug(System.LoggingLevel.DEBUG, ' Response From WhatsApp \n  '+ responseString);
        }else{
            response.responseBody = Blob.valueOf('{success:false, event:"Unknown","message:"'+responseValid+'"}');
            response.statusCode = 401;
            return;
        }
        
        response.statusCode = 200;
        response.responseBody = Blob.valueOf('{success:true, event:"success"}');
    }
    
    private static String validateWhatsAppSignature(RestRequest request, String responseString) {
        // Validate Stripe signature Start 
        Map<String, String> headers = request.headers;
        
        String whatsAppSignature = headers.get('X-Hub-Signature-256');
        
        String whatsAppPayload = RestContext.request.requestBody.toString();
        
        // Verify the signature using 'hmacSHA256'. I have the Webhook key stored in a Custom Label
        String whatsAppSecret = System.Label.WHATSAPPSECRET; // Facebook Application Secret Key
        Blob signedPayload = Crypto.generateMac('hmacSHA256', Blob.valueOf(whatsAppPayload), Blob.valueOf( whatsAppSecret ));
        
        String encodedPayload = 'sha256='+EncodingUtil.convertToHex(signedPayload);
        // Return status code based on whether signed payload matches or not
        
        String response = (encodedPayload == whatsAppSignature)? SIGNATURE_VALID_MESSAGE : SIGNATURE_NOT_VALID_MESSAGE;
        return response;
        // Validate Stripe signature End 
    }
}

I would appreciate any tips on how to tackle the issue.