ms graph php sdk set from name when sending email - php

Working off of the 'Send and email' example:
https://github.com/microsoftgraph/msgraph-sdk-php/wiki/Example-calls#send-an-email
I'm trying to set the 'from name' of the email in the header of the sent email to show 'TEST' instead of the name associated with my OWA account.
$graph = new Graph();
$graph->setAccessToken(access_token);
$mailBody = array( "Message" => array(
"subject" => $subject . ' ' . $from_name,
"body" => array(
"contentType" => "html",
"content" => $body
),
"sender" => array(
"emailAddress" => array(
"name" => "TEST",
"address" => $from_user->email
)
),
"from" => array(
"emailAddress" => array(
"name" => 'TEST',
"address" => $from_user->email
)
),
"toRecipients" => array(
array(
"emailAddress" => array(
"name" => $to_user->name,
"address" => $to_user->email
)
)
)
)
);
$response = $graph->createRequest("POST", "/me/sendMail")
->attachBody($mailBody)
->execute();
But the message header always has the name from my OWA (outlook) account instead.

AFAIK it is not supported to override name property of emailAddress resource via senMail endpoint.
But Microsoft Graph supports the feature which allows a user to send mail that appears to be sent from another user, distribution list, group, resource, or shared mailbox (official documentation)
Two mailbox permissions affect how a message is sent:
Send on Behalf
Send As
Below is demonstrated on how to sent mail from distribution group called Finance Department
POST https://graph.microsoft.com/v1.0/me/sendMail
{
"message": {
"subject": "Finance results",
"body": {
"contentType": "text",
"content": "Some finance results goes here..."
},
"toRecipients": [
{
"emailAddress": {
"address": "mary#contoso.onmicrosoft.com"
}
}
],
"from": {
"emailAddress": {
"address": "financedeplist#contoso.onmicrosoft.com"
}
}
}
}
Current user: Jon Doe (jdoe#contoso.onmicrosoft.com)
Option 1. Send on Behalf
Option 2. Send As

Related

Empty Payload. JSON content expected (guzzle, php, azur active directory and outlook)

I am a student in programming and I have difficulties with my projects, little documentation meets my expectations and I would need help.
in this project I have to send from my application the token, the json flow on outlook to schedule a meeting
about Project : the principle is on a page to create a meeting which will then be linked to the outlook calendar this document helped me a lot https://learn.microsoft.com/fr-fr/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http https://youtu.be/orVsKsRs2Us
(data is on another page)
the whole function
public function Postcalendrier($ID,$data) {
$token=$_SESSION['token'];
$ID=$_SESSION["ID"];
$calendarGroup="/calendarGroups/{myID}/";
$calendar="calendars/{myID}/events";
$urlcalendar="https://graph.microsoft.com/v1.0/users/".$ID;
$url=$urlcalendar.$calendarGroup.$calendar;
$headers = [
'Authorization' => 'Bearer '.$token->access_token,
'Accept' => 'application/json',
'Content-Type' => 'application/json',
];
$json = json_encode([$data])
$reponse = $this->guzzle->request('POST', $url,['headers' =>
$headers,'json' => $json],['debug' => true]);
return $response->getStatusCode();
}
$data = array(
"subject" => $Subject,
"body" => array(
"contentType" => "HTML",
"content" => $Content
),
"start" => array(
"dateTime" => $StartDateTime."T".$StartHourTime.":00",
"timeZone" => "$localDatetime"
),
"end" => array(
"dateTime" => $StartDateTime."T".$EndHourTime.":00",
"timeZone" => "$localDatetime"
),
"location" => array(
"displayName" => $Location
),
"attendees"=> [array(
"emailAddress"=> array(
"address"=> $addressmail,
"name"=>$prenom
),
"type"=> "required"
)]
);
I get this error message
Empty Payload. JSON content expected
so I tried with a different JSON but
I got this message instead and I don't really understand it
code UnableToDeserializePostBody message were unable to deserialize
this is my new json
$json = [
'json' => json_encode([$data])
];
thank you for your attention

Laravel - How to change FCM default notification tune

this question was asked before and was ignored, if you have a solution for it then your contribution is valuable, is there any way to change the default sound of the FCM notification if I'm using the below code, changing "sound"=>"arrive" to soundtrack path is not working?
thank you
public function toFcm($notifiable) {
$message = new FcmMessage();
$notification = [
'body' => trans('lang.notification_your_order', ['parcel_id' => $this->parcel->id, 'order_status' => $this->parcel->parcelStatus->status]),
'image' => Config::get('app.url').'/uploads/parcel.png',
'icon' => Config::get('app.url').'/uploads/parcel.png',
"title" => "Order Updated",
"content_available" => true,
"priority" => "high",
"sound"=>"arrive",
'id' => 'orders',
];
$data = [
'click_action' => "FLUTTER_NOTIFICATION_CLICK",
'id' => 'orders',
'status' => 'done',
'message' => $notification,
];
$message->content($notification)->data($data)->priority(FcmMessage::PRIORITY_HIGH);
return $message;
}
Ensure that the name of the sound matches the name of the sound installed inside the res/raw folder, then ensure your request is correctly formatted
example: "filename.mp3"
{
"token": "client_notification_token", <- or topic
"notification": {
"title": "Push notification title",
"body": "Push body",
"sound": "filename", <-- points to src/res/raw/filename.mp3
}
...
}
Source: https://medium.flatstack.com/migrate-to-api-26-push-notifications-with-custom-sound-vibration-light-14846ebc9e96

OTRS : Create Outgoing E-Mail-Ticket via Webservice

I am trying to create an Ticket via PHP & the REST genericinterface from OTRS (https://doc.otrs.com/doc/manual/admin/6.0/en/html/genericinterface.html#id-1.6.12.10.7.2).
I can create an Ticket and also an Article. But instead of an outgoing email the OTRS History looks like the user was sending a ticket to the queue. And also no mail is going out to the customer :-(.
But I like to have an outgoing EMail Ticket together with a pending state of the ticket.
Here my PHP code
<?php
header("Content-type: application/json; charset=utf-8");
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'http://test-otrs.company.local/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/']);
$arrTicket = array(
"Title" => 'some ticket title',
"Queue" => 'testqueue',
"Lock" => 'unlock',
"Type" => 'Unclassified',
"State" => 'new',
"Priority" => '3 normal',
"Owner" => 'username',
"CustomerUser" => 'user#test.com'
);
$arrArticle = array(
"CommunicationChannel" => 'Email',
"SenderType" => 'agent',
"To" => 'user#test.com',
"Subject" => 'some subject',
"Body" => 'some body',
"ContentType" => 'text/plain; charset=utf8'
);
$response = $client->post('Ticket', ['json' => array("UserLogin" => "username", "Password" => "testtesttest", "Ticket" => $arrTicket, "Article" => $arrArticle)]);
if ($response->getBody())
{
echo $response->getBody();
}
https://forums.otterhub.org/viewtopic.php?p=168025#p168025 solved my problem. You need a extra plugin (https://github.com/znuny/Znuny4OTRS-GIArticleSend) to be able to send an outgoing EMail Ticket.

Send message via socket to a specific client with PHP Socket.IO

I need to send a message to a client connected to a socket server but I need it to only be sent to a person, and not a broadcast as such. I have read that with the function to() of socket.IO it can be but I have implemented it in several ways and I do not get it, I send it to all.
this is my code
...
$socket->on('new message', function($message) use($socket)
{
$socket->emit("new message", array(
"username" => $socket->username,
"action" => "me",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "user", "time" => date('H:i'), "message" => $message ]
)
);
//I NEED HELP HERE, PLEASE
$socket->broadcast->emit("new message", array(
"username" => $socket->username,
"action" => "chat",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "", "time" => date('H:i'), "message" => $message ]
));
});
...
From the Socket.IO cheatsheet:
// sending to individual socketid (private message)
io.to(`${socketId}`).emit('hey', 'I just met you');
So for you, it's something like:
//I NEED HELP HERE, PLEASE
io->to($socketId)->emit("new message", array(
"username" => $socket->username,
"action" => "chat",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "", "time" => date('H:i'), "message" => $message ]
));
Note: you need to store (in array) the ids ($socket->id) of the clients when they connected, and use the one you need as $socketId in the example above.

Telegram Inline Bot shows nothing inline

i am trying to create an inline bot for telegram with php. I have followed the steps with the BotFather. I have created the bot, taken the token, setinline and set the placeholder message. I have set the webhook and it's working. But when i type the bot in the message i do get nothing and if I send the message, just nothing happen. The webhook is working, I have tried it with normal messages.
This is my code, after a while I just give up and get it from a blog, edited it a bit.
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
//sendMessage(print_r($update,true), $chatID);
if (isset($update["inline_query"])) {
$inlineQuery = $update["inline_query"];
$queryId = $inlineQuery["id"];
$queryText = $inlineQuery["query"];
if (isset($queryText) && $queryText !== "") {
apiRequestJson("answerInlineQuery", [
"inline_query_id" => $queryId,
"results" => ($queryText),
"cache_time" => 86400,
]);
}
else {
apiRequestJson("answerInlineQuery", [
"inline_query_id" => $queryId,
"results" => [
[
"type" => "article",
"id" => "0",
"title" => "TEST",
"message_text" => "TEST",
],
]
]);
}
}
The bot still show me nothing.
I think i just skipped a step.
The results need to have the key message_text inside the input_message_content.Therefore a result could look like this:
$results = array(
array(
"type" => "article",
"id" => "1",
"title" => "Title",
"description" => "Description",
"input_message_content" => array(
"message_text" => "<code>Message 1</code>",
"parse_mode" => "HTML"
)
)
);
$postData = array(
"inline_query_id" => $inlineQuery["id"],
"results" => json_encode($results),
"cache_time" => 0
);

Categories