Skip to content

Instantly share code, notes, and snippets.

@vgrovestine
Created August 26, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrovestine/1949c22996998f7368d34a596ab0a8a4 to your computer and use it in GitHub Desktop.
Save vgrovestine/1949c22996998f7368d34a596ab0a8a4 to your computer and use it in GitHub Desktop.
Simple utility to chat directly with a person via Microsoft Teams given their email address, without need to manually search for that particular individual in the application.
<?php
// Usage:
// https://mysite.xyz/chatwith.php?person=ME@MYSITE.XYZ
//
// Logging:
// Saved as ../chatwith_log/YYYY-MM.csv
// Write permissions required for web server.
//
// Reference:
// https://www.msoutlook.info/question/teams-chat-link-in-email-signature
// https://teams.microsoft.com/l/chat/0/0?users=<youremailaddress>
function isValidEmail($email) {
if(preg_match('/^[a-z0-9._%+-]+@(MYSITE\.XYZ)$/i', $email)) {
// **
// ** IMPORTANT: Change "MYSITE\.XYZ", above, to your own email domain.
// **
return true;
}
return false;
}
$person = (array_key_exists('person', $_GET) ? trim(urldecode($_GET['person'])) : false);
$loginfo = array(
date('Y-m-d H:i:s'),
$person,
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI'],
$_SERVER['HTTP_REFERER'],
$_SERVER['REMOTE_ADDR'],
$_SERVER['HTTP_USER_AGENT']
);
$fp = fopen('../chatwith_log/' . date('Y-m') . '.csv', 'a');
fputcsv($fp, $loginfo);
fclose($fp);
if(!isValidEmail($person)) {
die('Usage: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?person=&lt;firstname.lastname@acadiau.ca&gt;');
}
header('Location: https://teams.microsoft.com/l/chat/0/0?users=' . $person);
exit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment