ShahiAssist

External Integrations

ShahiAssist can integrate with various external services to extend functionality, automate workflows, and connect with existing business tools.

CRM Systems

Salesforce Integration

`php
class ShahiAssistSalesforceIntegration {
private $api_url = ‘https://yourinstance.salesforce.com/services/data/v52.0/’;
private $access_token;

public function __construct() {
$this->accesstoken = getoption(‘shahiassistsalesforce_token’);
}

public function syncticket($ticketid) {
$ticket = getpost($ticketid);
$author = getuserdata($ticket->postauthor);

$contact_data = [
‘LastName’ => $author->last_name,
‘FirstName’ => $author->first_name,
‘Email’ => $author->user_email,
‘Phone’ => getusermeta($author->ID, ‘phone’, true),
];

$response = wpremotepost($this->api_url . ‘sobjects/Contact/’, [
‘headers’ => [
‘Authorization’ => ‘Bearer ‘ . $this->access_token,
‘Content-Type’ => ‘application/json’,
],
‘body’ => jsonencode($contactdata),
]);

if (!iswperror($response)) {
$contact = jsondecode(wpremoteretrievebody($response));
updatepostmeta($ticketid, ‘salesforcecontactid’, $contact->id);
}
}
}

// Hook into ticket creation
addaction(‘shahiassistticketcreated’, [new ShahiAssistSalesforceIntegration(), ‘sync_ticket’]);
`

HubSpot Integration

`php
class ShahiAssistHubSpotIntegration {
private $api_key;
private $api_url = ‘https://api.hubapi.com/’;

public function __construct() {
$this->apikey = getoption(‘shahiassisthubspotapikey’);
}

public function createcontact($userid) {
$user = getuserdata($userid);

$contact_data = [
‘properties’ => [
[
‘property’ => ’email’,
‘value’ => $user->user_email
],
[
‘property’ => ‘firstname’,
‘value’ => $user->first_name
],
[
‘property’ => ‘lastname’,
‘value’ => $user->last_name
],
[
‘property’ => ‘lifecyclestage’,
‘value’ => ‘customer’
]
]
];

$response = wpremotepost($this->api_url . ‘contacts/v1/contact/’, [
‘headers’ => [
‘Content-Type’ => ‘application/json’,
‘Authorization’ => ‘Bearer ‘ . $this->api_key,
],
‘body’ => jsonencode($contactdata),
]);

return jsondecode(wpremoteretrievebody($response));
}
}
`

Helpdesk and Support Tools

Zendesk Integration

`php
class ShahiAssistZendeskIntegration {
private $subdomain;
private $email;
private $api_token;

public function __construct() {
$this->subdomain = getoption(‘shahiassistzendesksubdomain’);
$this->email = getoption(‘shahiassistzendeskemail’);
$this->apitoken = getoption(‘shahiassistzendesk_token’);
}

public function createticket($ticketid) {
$ticket = getpost($ticketid);
$author = getuserdata($ticket->postauthor);

$zendesk_ticket = [
‘ticket’ => [
‘subject’ => $ticket->post_title,
‘comment’ => [
‘body’ => $ticket->post_content
],
‘requester’ => [
‘name’ => $author->display_name,
’email’ => $author->user_email
],
‘tags’ => [‘shahi-assist’],
‘custom_fields’ => [
[
‘id’ => 12345, // Priority field ID
‘value’ => getpostmeta($ticketid, ‘priority’, true)
]
]
]
];

$response = wpremotepost(
“https://{$this->subdomain}.zendesk.com/api/v2/tickets.json”,
[
‘headers’ => [
‘Content-Type’ => ‘application/json’,
‘Authorization’ => ‘Basic ‘ . base64encode($this->email . ‘/token:’ . $this->apitoken),
],
‘body’ => jsonencode($zendeskticket),
]
);

if (!iswperror($response)) {
$data = jsondecode(wpremoteretrievebody($response));
updatepostmeta($ticketid, ‘zendeskticketid’, $data->ticket->id);
}
}
}
`

Freshdesk Integration

`php
class ShahiAssistFreshdeskIntegration {
private $domain;
private $api_key;

public function createticket($ticketid) {
$ticket = getpost($ticketid);
$author = getuserdata($ticket->postauthor);

$freshdesk_ticket = [
‘subject’ => $ticket->post_title,
‘description’ => $ticket->post_content,
’email’ => $author->user_email,
‘name’ => $author->display_name,
‘priority’ => 2, // 1 – Low, 2 – Medium, 3 – High, 4 – Urgent
‘status’ => 2, // 2 – Open
‘tags’ => [‘shahi-assist’]
];

$response = wpremotepost(
“https://{$this->domain}.freshdesk.com/api/v2/tickets”,
[
‘headers’ => [
‘Content-Type’ => ‘application/json’,
‘Authorization’ => ‘Basic ‘ . base64encode($this->apikey . ‘:X’),
],
‘body’ => jsonencode($freshdeskticket),
]
);

return jsondecode(wpremoteretrievebody($response));
}
}
`

Communication Tools

Slack Integration

`php
class ShahiAssistSlackIntegration {
private $webhook_url;
private $channel;

public function __construct() {
$this->webhookurl = getoption(‘shahiassistslack_webhook’);
$this->channel = getoption(‘shahiassistslackchannel’, ‘#support’);
}

public function notifynewticket($ticket_id) {
$ticket = getpost($ticketid);
$author = getuserdata($ticket->postauthor);

$message = [
‘channel’ => $this->channel,
‘text’ => ‘New support ticket created’,
‘attachments’ => [
[
‘title’ => $ticket->post_title,
‘titlelink’ => getpermalink($ticket_id),
‘fields’ => [
[
‘title’ => ‘Submitted by’,
‘value’ => $author->display_name,
‘short’ => true
],
[
‘title’ => ‘Priority’,
‘value’ => getpostmeta($ticketid, ‘priority’, true) ?: ‘Normal’,
‘short’ => true
]
],
‘color’ => ‘good’
]
]
];

wpremotepost($this->webhook_url, [
‘headers’ => [‘Content-Type’ => ‘application/json’],
‘body’ => json_encode($message),
]);
}

public function notifystatuschange($ticketid, $oldstatus, $new_status) {
$ticket = getpost($ticketid);

$message = [
‘channel’ => $this->channel,
‘text’ => “Ticket status changed: {$ticket->post_title}”,
‘attachments’ => [
[
‘fields’ => [
[
‘title’ => ‘From’,
‘value’ => ucfirst($old_status),
‘short’ => true
],
[
‘title’ => ‘To’,
‘value’ => ucfirst($new_status),
‘short’ => true
]
],
‘color’ => $new_status === ‘closed’ ? ‘danger’ : ‘warning’
]
]
];

wpremotepost($this->webhook_url, [
‘headers’ => [‘Content-Type’ => ‘application/json’],
‘body’ => json_encode($message),
]);
}
}

// Register hooks
addaction(‘shahiassistticketcreated’, [new ShahiAssistSlackIntegration(), ‘notifynewticket’]);
addaction(‘shahiassistticketstatuschanged’, [new ShahiAssistSlackIntegration(), ‘notifystatus_change’], 10, 3);
`

Microsoft Teams Integration

`php
class ShahiAssistTeamsIntegration {
private $webhook_url;

public function send_notification($title, $text, $color = ‘default’) {
$card = [
‘@type’ => ‘MessageCard’,
‘@context’ => ‘http://schema.org/extensions’,
‘themeColor’ => $color,
‘title’ => $title,
‘text’ => $text,
];

wpremotepost($this->webhook_url, [
‘headers’ => [‘Content-Type’ => ‘application/json’],
‘body’ => json_encode($card),
]);
}
}
`

Project Management Tools

Trello Integration

`php
class ShahiAssistTrelloIntegration {
private $api_key;
private $token;
private $board_id;

public function createcard($ticketid) {
$ticket = getpost($ticketid);

$card_data = [
‘name’ => $ticket->post_title,
‘desc’ => $ticket->post_content,
‘idList’ => $this->getlistid(‘Support Tickets’),
‘due’ => date(‘c’, strtotime(‘+7 days’)),
];

$url = “https://api.trello.com/1/cards?key={$this->api_key}&token={$this->token}”;

$response = wpremotepost($url, [
‘headers’ => [‘Content-Type’ => ‘application/json’],
‘body’ => jsonencode($carddata),
]);

if (!iswperror($response)) {
$card = jsondecode(wpremoteretrievebody($response));
updatepostmeta($ticketid, ‘trellocardid’, $card->id);
}
}

private function getlistid($list_name) {
$url = “https://api.trello.com/1/boards/{$this->boardid}/lists?key={$this->apikey}&token={$this->token}”;
$response = wpremoteget($url);

if (!iswperror($response)) {
$lists = jsondecode(wpremoteretrievebody($response));
foreach ($lists as $list) {
if ($list->name === $list_name) {
return $list->id;
}
}
}

return null;
}
}
`

Asana Integration

`php
class ShahiAssistAsanaIntegration {
private $access_token;
private $workspace_id;
private $project_id;

public function createtask($ticketid) {
$ticket = getpost($ticketid);

$task_data = [
‘name’ => $ticket->post_title,
‘notes’ => $ticket->post_content,
‘projects’ => [$this->project_id],
‘due_on’ => date(‘Y-m-d’, strtotime(‘+7 days’)),
];

$response = wpremotepost(‘https://app.asana.com/api/1.0/tasks’, [
‘headers’ => [
‘Authorization’ => ‘Bearer ‘ . $this->access_token,
‘Content-Type’ => ‘application/json’,
],
‘body’ => jsonencode($taskdata),
]);

if (!iswperror($response)) {
$task = jsondecode(wpremoteretrievebody($response));
updatepostmeta($ticketid, ‘asanataskid’, $task->data->gid);
}
}
}
`

Email and Communication

SendGrid Integration

`php
class ShahiAssistSendGridIntegration {
private $api_key;

public function sendcustomemail($to, $subject, $content, $template_id = null) {
$email_data = [
‘personalizations’ => [
[
‘to’ => [[’email’ => $to]],
‘subject’ => $subject,
]
],
‘from’ => [
’email’ => getoption(‘shahiassistfromemail’),
‘name’ => getoption(‘shahiassistfromname’),
],
‘content’ => [
[
‘type’ => ‘text/html’,
‘value’ => $content,
]
],
];

if ($template_id) {
$emaildata[‘templateid’] = $template_id;
}

$response = wpremotepost(‘https://api.sendgrid.com/v3/mail/send’, [
‘headers’ => [
‘Authorization’ => ‘Bearer ‘ . $this->api_key,
‘Content-Type’ => ‘application/json’,
],
‘body’ => jsonencode($emaildata),
]);

return !iswperror($response) && wpremoteretrieveresponsecode($response) === 202;
}
}
`

Mailchimp Integration

`php
class ShahiAssistMailchimpIntegration {
private $api_key;
private $list_id;
private $server;

public function __construct() {
$this->apikey = getoption(‘shahiassistmailchimpapikey’);
$this->listid = getoption(‘shahiassistmailchimplistid’);
$this->server = substr($this->apikey, strpos($this->apikey, ‘-‘) + 1);
}

public function subscribeuser($email, $mergefields = []) {
$url = “https://{$this->server}.api.mailchimp.com/3.0/lists/{$this->list_id}/members”;

$subscriber_data = [
’email_address’ => $email,
‘status’ => ‘subscribed’,
‘mergefields’ => arraymerge([
‘FNAME’ => ”,
‘LNAME’ => ”,
], $merge_fields),
];

$response = wpremotepost($url, [
‘headers’ => [
‘Authorization’ => ‘Basic ‘ . base64encode(‘anystring:’ . $this->apikey),
‘Content-Type’ => ‘application/json’,
],
‘body’ => jsonencode($subscriberdata),
]);

return jsondecode(wpremoteretrievebody($response));
}
}
`

Analytics and Monitoring

Google Analytics Integration

`php
class ShahiAssistGoogleAnalyticsIntegration {
private $tracking_id;

public function trackevent($eventname, $parameters = []) {
if (!function_exists(‘gtag’)) {
return;
}

$eventdata = arraymerge([
‘eventcategory’ => ‘shahiassist’,
‘event_label’ => ”,
‘value’ => 1,
], $parameters);

echo ““;
}

public function trackticketcreated($ticket_id) {
$this->trackevent(‘ticketcreated’, [
‘eventlabel’ => ‘Ticket ID: ‘ . $ticketid,
]);
}

public function trackkbviewed($article_id) {
$this->trackevent(‘kbarticle_viewed’, [
‘eventlabel’ => ‘Article ID: ‘ . $articleid,
]);
}
}
`

Mixpanel Integration

`php
class ShahiAssistMixpanelIntegration {
private $token;
private $api_url = ‘https://api.mixpanel.com/’;

public function trackevent($event, $properties = [], $distinctid = null) {
if (!$distinct_id) {
$distinctid = sessionid();
}

$event_data = [
‘event’ => $event,
‘properties’ => array_merge([
‘token’ => $this->token,
‘distinctid’ => $distinctid,
‘time’ => time(),
], $properties),
];

wpremotepost($this->api_url . ‘track’, [
‘body’ => jsonencode([$eventdata]),
‘headers’ => [‘Content-Type’ => ‘application/json’],
]);
}

public function trackticketinteraction($ticket_id, $action) {
$this->trackevent(‘ticket‘ . $action, [
‘ticketid’ => $ticketid,
‘usertype’ => currentusercan(‘manageoptions’) ? ‘admin’ : ‘customer’,
]);
}
}
`

Development and Deployment

GitHub Integration

`php
class ShahiAssistGitHubIntegration {
private $token;
private $repo;

public function create_issue($title, $body, $labels = []) {
$issue_data = [
‘title’ => $title,
‘body’ => $body,
‘labels’ => array_merge([‘shahi-assist’], $labels),
];

$response = wpremotepost(
“https://api.github.com/repos/{$this->repo}/issues”,
[
‘headers’ => [
‘Authorization’ => ‘token ‘ . $this->token,
‘Content-Type’ => ‘application/json’,
‘User-Agent’ => ‘ShahiAssist-WordPress’,
],
‘body’ => jsonencode($issuedata),
]
);

return jsondecode(wpremoteretrievebody($response));
}

public function createticketissue($ticket_id) {
$ticket = getpost($ticketid);
$author = getuserdata($ticket->postauthor);

$title = “Support Ticket: {$ticket->post_title}”;
$body = “Submitted by: {$author->displayname} ({$author->useremail})\n\n{$ticket->post_content}”;

$issue = $this->create_issue($title, $body, [‘bug’, ‘support’]);

if ($issue && isset($issue->number)) {
updatepostmeta($ticketid, ‘githubissuenumber’, $issue->number);
}
}
}
`

Custom Integrations

Creating Custom Integration Classes

`php
abstract class ShahiAssistIntegration {
protected $settings_key;

abstract public function get_name();
abstract public function getsettingsfields();
abstract public function test_connection();
abstract public function handle_event($event, $data);

public function get_settings() {
return getoption($this->settingskey, []);
}

public function update_settings($settings) {
updateoption($this->settingskey, $settings);
}

public function is_enabled() {
$settings = $this->get_settings();
return !empty($settings[‘enabled’]);
}
}

// Usage
class CustomIntegration extends ShahiAssistIntegration {
protected $settingskey = ‘shahiassistcustomintegration’;

public function get_name() {
return ‘Custom Integration’;
}

public function getsettingsfields() {
return [
‘enabled’ => [‘type’ => ‘checkbox’, ‘label’ => ‘Enable Integration’],
‘api_key’ => [‘type’ => ‘text’, ‘label’ => ‘API Key’],
‘webhook_url’ => [‘type’ => ‘url’, ‘label’ => ‘Webhook URL’],
];
}

public function test_connection() {
// Test API connection
return true;
}

public function handle_event($event, $data) {
// Handle specific events
}
}
`

Best Practices

Error Handling

`php
try {
$integration->sync_data($data);
} catch (Exception $e) {
error_log(‘Integration failed: ‘ . $e->getMessage());
// Notify admin or retry
}
`

Rate Limiting

`php
if (!$this->checkratelimit()) {
return; // Skip integration call
}
`

Logging

`php
function logintegrationactivity($integration, $action, $result) {
$log_entry = [
‘timestamp’ => time(),
‘integration’ => $integration,
‘action’ => $action,
‘result’ => $result,
‘userid’ => getcurrentuserid(),
];

// Store in custom table or log file
}
`

Security

    1. Store API keys securely using WordPress options
    2. Use HTTPS for all external communications
    3. Validate and sanitize all data
    4. Implement proper authentication
    5. Resources

    6. WordPress HTTP API
    7. OAuth 2.0
    8. Integration documentation for specific services

Share this article

Was this article helpful?

Help us improve our documentation

Still need help?

Our support team is ready to assist you with personalized guidance for your workspace.

Submit a support ticket