I program the bot telegram.
I want Get message_id By Bot ,when I sent a message to Group.
My Code is PHP.
$token = "MY_BOT's_TOKEN";
$data = [
'text' => 'my message here',
'chat_id' => 'the_chat_id_here'
];
file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );
How Do it?
best regard.
Your file_get_contents call returns a result containing status code and messageId.
$result = file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );
Related
I am writing a telegram to the php bot, it works fine, but it sends the same message many times, it needs to be sent once, can anyone help me? here is my code
function chat_telegram( )
{
$token = <token>;
$telegram = "https://api.telegram.org/bot" . $token;
$query = http_build_query([
'chat_id' => <chat_id>,
'text' => 'I love pizza'
]);
$response = file_get_contents( $telegram . '/sendMessage?' . $query );
return $response;
}
I am using twilio to send sms to mobile, when i run the script it sends an SMS like it should to my mobile but the problem is i don't know the status of the sent SMS, how do i get that?
What i tried so far is below
<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]
// A Twilio number you own with SMS capabilities
$twilio_number = "+0987654321";
$client = new Client($account_sid, $auth_token);
$client->messages->create(
// Where to send a text message (your cell phone?)
'+1234567890',
array(
'from' => $twilio_number,
'body' => 'I sent this message in under 10 minutes!'
)
);
after doing proper research, and having all kind of issues with the webhook, here is what i settled on
$phoneString = $phoneNumber->asNorthAmericanDialingString();
$mi = $client->messages->create(
// the number you'd like to send the message to
$phoneString ,
array (
// A Twilio phone number you purchased at twilio.com/console
'from' => Config::getCurrentConfig()->smsConfig->fromNumber ,
// the body of the text message you'd like to send
'body' => $message ,
'ProvideFeedback' => "true"
)
);
$msg = $mi->fetch();
$sid = $msg->sid;
$status = $msg->status;
if ($status == 'sent' || $status == 'delivered') { // f'ing twilio, random status
self::getClassLogger()->debug("Sent text message[$sid], status is [$status]");
return new TextMessageStatus($sid , $status);
} else {
// do whatever is appropriate for your case
}
I'm trying to create a Telegram API bot for clients registration , so I chose the ' setWebHook ' method and wrote some codes :
<?php
include("config.php");
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$user_id = $update["message"]["chat"]["id"];
if( $update["message"]["text"] == "/start" OR $update["message"]["text"] == "/menu" ){
$keyboard = array(
'keyboard' => array(
array("📝 Register","🔑 Login")
),'one_time_keyboard'=>true,'resize_keyboard'=>true);
$replyKeyboard = json_encode($keyboard);
$replyMessage = "Hello 😊
Welcome to our bot ✋🏼
What do you want to do ?
.
";
}
if( $update["message"]["text"] == "📝 Register"){
$replyMessage = "Please enter username :";
}
$url = $bot_url.'sendMessage';
$data = array('chat_id' => $user_id,'text' => $replyMessage,'parse_mode' => 'Markdown','reply_markup' => $replyKeyboard );
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$update = #file_get_contents($url, false, $context);
?>
Ok so the robot shows the options for register or login , and when you choose register , it asks you username. It's ok up to here but ,
what I have to do for the rest of the registration process ??
How should I grab username and store it in database and after that grab password and store it and for other informations ?
I appreciate any logical ways for registering by telegram bots.
I wish I could completely describe my problem , I need your help my friends.
Thank you
( config.php includes database and bot token information )
As I understand from your question these are some tips maybe helpful for you:
Each message that delivers from telegram (users) have an id that tell which user sends the message(==chat_id a unique number).
Your bot should log messages and save the important parts of messages in a db. In this manner you have a track of user's conversation with your bot and you can recognize that for which question of your bot ,user answers. If you look for each Json object delivers from telegram you can see which data telegram reveals from user.
I guess I have read all past posts about the argument, but I was wondering if something has changed on topic.
Is it now possible to mention a page inside a message text using Facebook PHP SDK?
Something like this:
$post_params = array(
'access_token' => PAGE_TOKEN,
'message' => 'This is a message tagged to #[PAGE_ID]
);
$postStream = $this->facebook->api("/" . PAGE_ID . "/feed", 'post', $post_params);
I am referring to this page: https://developers.facebook.com/docs/opengraph/guides/tagging/
Actually, so far, I solved the problem the following way:
1) "Normalize" the page name through a regex replacement of possible "facebook related" uri
$replacePattern = '((https|http)?(:\/\/)?(www\.)?(facebook\.com)?(\/)?)';
$page_name = preg_replace($replacePattern, '', $page_name);
$page_name = 'https://www.facebook.com/' . $page_name;
2) Make a call to Facebook API using the "normalized" uri:
$fql = "SELECT id, name FROM profile WHERE id in (SELECT id FROM object_url WHERE url='" . $page_name . "')";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$response = $facebook->api($param);
i have an application that authenticates users through the linkedin api:
is it possible for an application to send messages to all users who authorized it? (ie: the app's system notifications)
is it possible to send a message to a subset of the application users? (ie: gold members etc. you can assume i have all the linkedin IDs stored somewhere)
i've been looking for a while, and can't find anything/
Something like this
function message($subject, $body, $recipients)
{
if (!is_array($recipients)) {
throw new Exception('Recipients must be suplied as an array');
}
// Start document
$xml = new DOMDocument('1.0', 'utf-8');
// Create element for recipients and add each recipient as a node
$elemRecipients = $xml->createElement('recipients');
foreach ($recipients as $recipient) {
// Create person node
$person = $xml->createElement('person');
$person->setAttribute('path', '/people/' . (string) $recipient);
// Create recipient node
$elemRecipient = $xml->createElement('recipient');
$elemRecipient->appendChild($person);
// Add recipient to recipients node
$elemRecipients->appendChild($elemRecipient);
}
// Create mailbox node and add recipients, body and subject
$elemMailbox = $xml->createElement('mailbox-item');
$elemMailbox->appendChild($elemRecipients);
$elemMailbox->appendChild($xml->createElement('body', ($body)));
$elemMailbox->appendChild($xml->createElement('subject', ($subject)));
// Append parent node to document
$xml->appendChild($elemMailbox);
$response = fetch('POST','/v1/people/~/mailbox', $xml->saveXML());
return ($response);
}
function fetch($method, $resource, $body = '') {
$params = array('oauth2_access_token' => $_SESSION['access_token'],
'format' => 'json',
);
// Need to use HTTPS
$url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
// Tell streams to make a (GET, POST, PUT, or DELETE) request
$context = stream_context_create(
array('http' =>
array('method' => $method,
'header'=> "Content-Type:text/xml\r\n"
. "Content-Length: " . strlen($body) . "\r\n",
'content' => ($body)
)
)
);
// Hocus Pocus
$fp = fopen($url, 'r', false, $context);
$response = file_get_contents($url, false, $context);
$result =json_decode($response,true);
return $result;}
message('Subject', 'body', array('id'));
function fetch from Code Sample
The only messaging supported by the API is via the Messaging API, which only allows for messages to be sent from one connection to another... so in theory, you (as in you the developer, not the application itself, as it has no connections) could send a message to any of your applications user's that you also happen to be connected to in some way. The Messaging API is pretty clear though that messages must be triggered by a specific action, and the maximum number of recipients is 10.
So the short answer is, not possible, although the above may be a bit of a workaround. An alternative would be to ask the user directly for their email address once they have completed the LI process and then you can contact them as you wish without running into API limits/restrictions.