With the help of the following steps, you will be able to do the integration of MailPoet with Groupboss:
- Before you do the integration, there are some additional steps you need to follow:
- Go to your WordPress (WP) dashboard. Then from the left side toolbar go to; Plugins >> Add New Plugin
- Now find ‘WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager’, or ‘Code Snippets’ and activate one of the plugins or both.
- Once the activation of the plugins is done– go to Snippets >> Add New.
- Then a new interface will be generated.
- Now copy and paste the below code (Code Preview) in the box. Scroll down and click the option ‘Run snippet everywhere’ below the code snippet box. Then click Save Changes and Activate. A new notification will come at the top with Snippet activated and created.
Code Preview
// Function to add a subscriber to MailPoet lists (POST request)
function prefix_add_mailpoet_subscriber(WP_REST_Request $request) {
// Get subscriber data from the request body
$email = sanitize_email($request->get_param('email'));
$first_name = sanitize_text_field($request->get_param('first_name'));
$last_name = sanitize_text_field($request->get_param('last_name'));
$list_ids = $request->get_param('list_ids');
// Validate email
if (empty($email) || !is_email($email)) {
return new WP_Error('invalid_email', 'Invalid or missing email address.', array('status' => 400));
}
// Validate first name
if (empty($first_name)) {
return new WP_Error('missing_first_name', 'First name is required.', array('status' => 400));
}
// Validate list IDs
if (empty($list_ids) || !is_array($list_ids)) {
return new WP_Error('invalid_list_ids', 'List IDs are required and must be an array.', array('status' => 400));
}
try {
// Use the MailPoet API to add the subscriber
$mailpoet_api = \MailPoet\API\API::MP('v1');
$subscriber_data = array(
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
);
// Options for MailPoet email notifications
$options = array(
'send_confirmation_email' => true, // Send confirmation email if needed
'schedule_welcome_email' => true, // Schedule a welcome email if applicable
'send_admin_notification_email' => true, // Notify admin of the new subscription
);
// Add the subscriber and return a success response
$subscriber = $mailpoet_api->addSubscriber($subscriber_data, $list_ids, $options);
return new WP_REST_Response(array(
'status' => 'success',
'message' => 'Subscriber added successfully!',
'subscriber' => $subscriber,
), 200);
} catch (Exception $e) {
// Handle errors gracefully
return new WP_Error('mailpoet_error', $e->getMessage(), array('status' => 400));
}
}
// Function to check if a MailPoet list ID is valid (GET request)
function prefix_check_mailpoet_list_id(WP_REST_Request $request) {
$list_id = (int) $request->get_param('id');
try {
// Use MailPoet API to get all lists
$mailpoet_api = \MailPoet\API\API::MP('v1');
$lists = $mailpoet_api->getLists(); // Get all lists
// Check if the provided list ID exists in the lists array
$is_valid = false;
foreach ($lists as $list) {
if ($list['id'] == $list_id) {
$is_valid = true;
break;
}
}
if ($is_valid) {
return new WP_REST_Response(array(
'status' => 'success',
'message' => 'List ID is valid.',
'list_id' => $list_id,
), 200);
} else {
return new WP_REST_Response(array(
'status' => 'error',
'message' => 'List ID is invalid or does not exist.',
), 404);
}
} catch (Exception $e) {
// Handle any MailPoet API exceptions
return new WP_REST_Response(array(
'status' => 'error',
'message' => $e->getMessage(),
), 400);
}
}
// Register REST API routes for MailPoet
function prefix_register_mailpoet_routes() {
// Check if MailPoet is active
if (class_exists('\MailPoet\API\API')) {
// Route to check if a list ID is valid
register_rest_route('mailpoet/v1', '/check-listid/(?P\d+)', array(
'methods' => 'GET',
'callback' => 'prefix_check_mailpoet_list_id',
'args' => array(
'id' => array(
'validate_callback' => function($param, $request, $key) {
return is_numeric($param);
}
),
),
));
// Route to add a subscriber to MailPoet lists
register_rest_route('mailpoet/v1', '/add-subscriber', array(
'methods' => 'POST',
'callback' => 'prefix_add_mailpoet_subscriber',
'permission_callback' => '__return_true', // Adjust this for better security
));
// Test route (ping) to check if MailPoet is active
register_rest_route('mailpoet/v1', '/ping', array(
'methods' => 'GET',
'callback' => function() {
return new WP_REST_Response(array(
'message' => 'MailPoet API is working.',
'status' => 'success',
), 200);
},
));
} else {
// Fallback route if MailPoet is not activated
register_rest_route('mailpoet/v1', '/ping', array(
'methods' => 'GET',
'callback' => function() {
return new WP_REST_Response(array(
'message' => 'MailPoet is not activated.',
'status' => 'error',
), 404);
},
));
}
}
add_action('rest_api_init', 'prefix_register_mailpoet_routes');
- Then go to this link: https://groupboss.serv00.net/?res_route=/mailpoet/v1/ping and if your snippet is activated and working fine then a message will show stating MailPoet API is working and status Success. If this message comes then you can start following the next steps.
Now comes the main part of the integration. With the help of the following steps, you will be able to do the integration of MailPoet with Groupboss:
- First, go to the Chrome extension store. Then add the Groupboss extension, and click on the Groupboss extension icon.
- Furthermore, click on Configure My Group and select a Facebook group.
- Then go to Autoresponder and select MailPoet. Now click Next.
- Then you’ll be asked for the Site URL, Activation key, and List ID. To get all those, sign in and go back to your MailPoet account.
- From your WordPress Dashboard– first, copy and paste the link of the website in the Groupboss Chrome extension.
- Now go to MailPoet settings >> Key activation and find the activation key for the integration. Copy and paste it on the Groupboss Chrome extension.
- Then go to the MaiPoet Lists and select the List Name you want to store your automated emails from the Facebook group.
- Go to the URL and find the List number from there. Now copy and paste it on the Groupboss Chrome extension.
- Done! As you click on the Save button, the integration is successfully saved. Find your activated integration among the list of Currently activated by clicking the auto responder drop-down menu.
- Then go to your Facebook group’s homepage, find member request. Now accept a friend request who has answered all the questions by tapping Approve by Groupboss.
- Once you have approved, go to the MailPoet >> Subscribers and find the accepted member’s data.
This is the overall step-by-step summary of MailPoet integration with Groupboss to generate your lead automatically and ensure a sharp edge over your competitors.