I want to send premium emojis by Telegram bot (I have a premium account and created a bot with it), but when I try to send it (I send emojis to the premium account), unfortunately, the emoji is sent normally.
my code:
<?php
$entities = [
'type' => 'custom_emoji',
'offset' => 4,
'length' => 2,
'custom_emoji_id' => '5877565553761062314'
];
$url = "https://api.telegram.org/BotToken";
$url .= "/sendMessage?chat_id=UserChatId";
$url .= "&text=Hi 💻";
$url .= "&parse_mode=html";
$url .= "&entities=" . json_encode($entities);
echo $url;
file_get_contents($url);
Message should be like this:
This feature will be activated in the future.
https://telegram.org/faq_premium#q-can-i-buy-a-premium-subscription-for-my-bots
Related
I'm tring create a comment by Wordpress Rest API and I have a problem.
Creating works but I can't save comment with break lines.
In database I have:
line 1\nline 2\nline 3
What can I do before post request with text?
Is there any function in php that will add break lines instead of \n?
#edit
This is my curl post:
$parameters = '?post=' . $this->request->getVar('eventId') . '&content=' . $this->request->getVar('content');
if ($this->request->getVar('authorName')) {
$parameters .= '&author_name=' . $this->request->getVar('authorName');
}
try {
$apiComment = $curl->post('https://xxxx.xx/wp-json/wp/v2/comments' . $parameters, [
'headers' => [
'Accept' => 'application/json'
]
]);
This is from another api and it's string:
$this->request->getVar('content')
1 - from www
2 - from wp rest api
I want the same as 1.
It's solution:
str_replace(['\n'], '%0D%0A', $this->request->getVar('content'))
We are attempting to send an email to multiple recipients using the Mailgun PHP API.
We are running MG PHP lib version 2.8.1.
Our code does the following:
note: email address and domain changed for privacy reasons
log_debugger('g1', 'g1');
$params = array(
'from' => $msg_org . " <" . EMAIL_SENDER . ">",
'to' => array('joe#gmail.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"joe#gmail.com": {"first":"Joe", "id":1}}'
);
log_debugger('g1', 'g2');
# Make the call to the client.
$mgresult = $mgClient->messages()->send(MAILGUN_DOMAIN, $params);
log_debugger('g1', 'g3');
// if the email was accepted by Mailgun then indicate the member message was delivered
if ($mgresult->http_response_code >= 200 && $mgresult->http_response_code < 300) {
log_debugger('mgr', $mgresult->http_response_code);
// else the email was not accepted by mailgun so indicate the member message failed to be delivered
} else {
log_debugger('g1', 'g4');
}
The call is successfully getting to MG, but we are not getting any return from MG. We have been sending to MG successfully for sometime and now we are attempting to send to multiple email addresses at one time. Below is the data we are passing in as recorded by our debug log.
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g2
Here is the MG documentation - Notice the error: messages()-send should be messages()->send
require 'vendor/autoload.php';
use Mailgun\Mailgun;
// Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$params = array(
'from' => 'Excited User <YOU#YOUR_DOMAIN_NAME>',
'to' => array('bob#example.com, alice#example.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"bob#example.com": {"first":"Bob", "id":1},
"alice#example.com": {"first":"Alice", "id": 2}}'
);
// Make the call to the client.
$result = $mgClient->messages()-send($domain, $params);
Any help getting this to work would be greatly appreciated. Logged a ticket with MG, but no reply as of yet.
Method documented by MG for sending message is not quite correct. I had to change the call from:
$mgresult = $mailgun_client->messages()->send(MAILGUN_DOMAIN, array(
to:
$mgresult = $mailgun_client->sendMessage(MAILGUN_DOMAIN, array(
I am trying to tweet an image using php. I have read the documentation and followed a some tutorials. I don't have any problem when sending a message; however, it does not work with images. I can not find where my mistake is, can anyone help?? I would deeply appreciate it.
<?php
$comments = $_POST['comment'];
if (isset($_POST['Twitter']))
{
require_once('twitter/codebird-php/src/codebird.php');
\Codebird\Codebird::setConsumerKey("xxxxxx","xxxxxx");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("xxxxxx", "xxxxxxxxxx");
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
$reply = $cb->statuses_update($params);
echo "You have posted your message succesfully";
}
else{
echo "You havent posted anythingh";
}
?>
You need to supply Twitter the fully qualified URI to your image.
You have the following code:
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
Unfortunately, that's not a complete URL to an image, it's a relative URL. Instead, you need to provide something along the lines of this:
$params = array(
'status' => $comments,
'media[]' => "http://www.example.com/images/image1.jpg"
);
In addition, according to the Twitter API v1 documentation, you need to use statuses/update_with_media instead of statuses/update.
If you are using Twitter API v1, Twitter also recommends using v1.1 instead.
I have a script which should scrap selected email from the inbox. Everything works except BODY. Subject, date, sender and etc.. were scraped without problems but the body were returned like this:
VG9kYXkncyBGcmVlIGFuZCBCYXJnYWluIEJvb2tzCgpVcGRhdGUgUHJlZmVyZW5jZXM6ICBodHRw
Oi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9wcmVmZXJlbmNlcz9oPTZjNTgxNDEyYjkzMTdiMWZlNjc1
ZDcwNDFjODJhYTc5Ckludml0ZSBGcmllbmRzOiBodHRwOi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9p
bnZpdGU/aD02YzU4MTQxMmI5MzE3YjFmZTY3NWQ3MDQxYzgyYWE3OQpVbnN1YnNjcmliZTogaHR0
cDovL3d3dy5ib29rZ29yaWxsYS5jb20vdW5zdWJzY3JpYmU/aD02YzU4MTQxMmI5MzE3YjFmZTY3
NWQ3MDQxYzgyYWE3OQoKQWxsIHByaWNlcyB3ZXJlIHZlcmlmaWVkIGJ5IEJvb2tHb3JpbGxhIHBy
aW9yIHRvIHRoaXMgZW1haWwgYmVpbmcgc2VudCwgYnV0IHByaWNlcyBtYXkgY2hhbmdlIHdpdGhv
dXQgbm90aWNlIHNvIHBsZWFzZSB2ZXJpZnkgdGhhdCB0aGUgYm9vayBpcyBzdGlsbCBmcmVlIG9y
IGJhcmdhaW4gcHJpY2VkIGJlZm9yZSBjb25maXJtaW5nIHlvdXIgb3JkZXIuIFNvbWUgYm9va3Mg
bWF5IG5vdCBiZSBmcmVlIG91dHNpZGUgdGhlIFVuaXRlZCBTdGF0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= $this->email_main->getInboxDetails($data['inbox_id']); // select inbox data by inbox id
$message_id = $inbox_details['last_sended_email_id'] + 1;
$imap = imap_open('{'. $data['inbox_data']['inbox_server'] .'}INBOX', ''. $data['inbox_data']['inbox_email'] .'', ''. $data['inbox_data']['inbox_password'] .'');
if (!$imap)
$this->email_main->insertError(imap_last_error(), $data['inbox_data']['id']);
$header = imap_header($imap, $message_id);
$message = array(
'subject' => $header->subject,
'fromname' => $header->fromaddress,
'fromaddress' => $header->from[0]->mailbox.'#'.$header->from[0]->host,
'toaddress' => $header->toaddress,
'date' => $header->date,
'timestamp' => $header->udate,
'body' => imap_qprint(imap_fetchbody($imap, $message_id, 2)), // $message_id = 1
);
any ideas folks?
Your content is encoded in base64.
base64_decode($content);
Will decode it :)
Edit:
Decoded with http://www.base64decode.org/ to get 'Today's Free and Bargain Books'
I am using Graph API https://developers.facebook.com/docs/reference/api/#publishing with PHP SDK and I would like to send some data via HTTP POST method, as it's mentioned in documentation (e.g. add comment).
At https://developers.facebook.com/docs/reference/api/batch/ they say I should encode the body of HTTP POST request as ...should be formatted as a raw HTTP POST body string, similar to a URL query string. I can't get the combination of PHP functions to get this to work. In the example they claim following should work:
"body": "message=Test status update"
Well, that works. But what if I need to add other params? And how should be this string encoded? E.g. I have this:
$data = array('name' => 'Gargamel', 'occupation' => 'Freelancing Smurf Hunter');
How should I process it to get required format? Following does NOT work:
$batch = array();
$query = array(
'method' => 'POST',
'relative_url' => '/forrest/full/of/smurfs',
'body' => urldecode(http_build_query($data)),
);
$batch[] = $query;
$responses = $this->api('/?batch=' . json_encode($batch, JSON_HEX_AMP), 'POST');
I explored half of the Internet, but I can't find any more specific information about the format than the one mentioned above (raw HTTP POST similar to a URL query string).
Thanks for any suggestions!
using this: http://forum.developers.facebook.net/viewtopic.php?pid=331343#p331343
$batch_array[] = array(
'method' => 'POST',
'relative_url' => 'Relative url',
'body' => 'message=' . 'Your message' . '%26data=' . 'Your data' ,
);
This is my batch example code:
$graph_url = "https://graph.facebook.com/me/friends?access_token=" . $params['access_token'];
$friends = json_decode(file_get_contents($graph_url));
$batched_request = '[{"method":"GET","relative_url":"'.$friends->data[0]->id.'/likes"}';
for ($i = 1; $i < 20; $i++) {
$batched_request .= ',{"method":"GET","relative_url":"'.$friends->data[$i]->id.'/likes"}';
}
$batched_request .= ']';
$post_url = 'https://graph.facebook.com/?batch='
. $batched_request . '&access_token=' . $params['access_token'] . '&method=post';
$posts = file_get_contents($post_url);
for ($i = 0; $i < 20; $i++) {
$post = json_decode($posts[$i]->body);
echo($friends->data[$i]->id.' '.$friends->data[$i]->name);
//print_r($post);
}
Batch query limit 20 requests. You need to decode each part of batch query, see code above.