I am in a hurry of completing a telegram bot project. I am using Telegram bot sdk (https://telegram-bot-sdk.readme.io/) with Laravel. The problem is that I've stored all my users chat_id in database and while I am trying to send a message to all my users(I do consider Telegram limitations mentioned in its official docs) the app will be blocked and none of the users get any message. Here is the simple code $Telegram::sendMessage(['chat_id' => 'CHAT_ID', 'text' => 'Hello World']);
i remember i faced to your problem when i develop the telegram bot , i just use the method in my cladd to send messages and my problem is solved , this is the method based on the library :
use Telegram\Bot\Api;
public function sendMsg($botToken,$chat_id,$text)
{
$telegram = new Api($botToken);
$response = $telegram->sendMessage([
'chat_id' => $chat_id,
'text' => $text,
]);
return $response;
}
Related
I need to send a long message to a telegram group with a bot. The message comes from a wordpress site after placing an order,I need to send all raw data an order creates to the telegram. The bot and php code works so far, it is sending me the message if I type something basic, but when I put the order information it doesn´t send any message.
I am looking for some code that somehow parses this information and makes it url ready to send to telegram.
This is my code:
* SEND ORDER TO TELEGRAM GROUP
*/
$apiToken = "Token";
$data = [
'chat_id' => 'ChatId',
'text' => 'New Order, Open App'
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .http_build_query($data) );
/**
* SEND ORDER TO TELEGRAM GROUP
*/
Maybe someone did it already previously?
Thanks.
I'm trying to use the SMS gateway from smsgateway.me in a software that works in VFP.
Anyone can help me to implement the PHP code in VFP?
The code is in: https://smsgateway.me/sms-api-documentation/messag...
PHP Code:
require 'vendor/autoload.php';
use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;
// Configure client
$config = Configuration::getDefaultConfiguration();
$config->setApiKey('Authorization', 'your-token-here');
$apiClient = new ApiClient($config);
$messageClient = new MessageApi($apiClient);
// Sending a SMS Message
$sendMessageRequest1 = new SendMessageRequest([
'phoneNumber' => '07791064781',
'message' => 'test1',
'deviceId' => 1
]);
$sendMessageRequest2 = new SendMessageRequest([
'phoneNumber' => '07791064781',
'message' => 'test2',
'deviceId' => 2
]);
$sendMessages = $messageClient->sendMessages([
$sendMessageRequest1,
$sendMessageRequest2
]);
print_r($sendMessages);
Look into using Chilkat to send SMS through VFP, instead of the native foxpro ways.
Chilkat made it very easy for me, sending and receiving text messages (with or without media files) from within foxpro code. Where you can automate things, putting them into DO/ENDDO loops etc. I use Twilio services but the same concept should work with smsgateway.
Good luck,
Sime
Thanks for help.
I find another way, and use a Android APK to create a SMS gateway direct in the phone.
I gona post another asking for help
As per the official document, we can send push notification to multiple devices using a topic or device group. But the problem is it needs a common message and payload data for all devices.
I want to send different messages to all devices.
For example, below users should receive the following message on their
devices.
User Amit: Hello Amit, your request approved.
User Sandip: Hello Sandip, your request declined.
User Piyush: Hello Piyush, your request declined.
And so on..... to 200-300 users.
Is it possible to send this all messages in a single HTTP request using Firebase Cloud Messaging?
It is possible with the official Admin SDKs (see https://firebase.google.com/docs/cloud-messaging/send-message#send_a_batch_of_messages), but unfortunately, the REST API documentation doesn't include information on how to send batch requests (yet, at least I didn't find them so far), probably because it involves creating a special kind of multipart request and is not easy to set up.
So I would advise using an Admin SDK to do it. As I don't know how you've sent the messages in the past, please be warned that using an Admin SDK comes with some additional setup (e.g. creating/downloading a Service Account), compared to making "just" a cURL request.
So, if you don't have to use PHP, it's always wiser to use one of the official SDKs (see https://firebase.google.com/docs/admin/setup/)
If you do choose to stick with PHP, there is an unofficial Admin SDK for PHP at https://github.com/kreait/firebase-php that supports sending batch messages. (Disclaimer: I'm the maintainer of that SDK).
You can read more about it in the repo or specifically at https://firebase-php.readthedocs.io/en/latest/cloud-messaging.html#send-multiple-messages-at-once, but here is how it might look like for your situation if you decided to give the PHP SDK a try:
use Kreait\Firebase\Factory;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile('/path/to/service_account.json');
$users = [
['name' => 'Amit', 'is_approved' => true, 'registration_token' => '...'],
['name' => 'Sandip', 'is_approved' => false, 'registration_token' => '...'],
['name' => 'Piyush', 'is_approved' => true, 'registration_token' => '...'],
// ...
];
$messages = [];
foreach ($users as $user) {
$statusText = $user['is_approved'] ? 'approved' : 'denied';
$messages[] = CloudMessage::withTarget('token', $user['registration_token'])
->withNotification([
'title' => "Your request was {$statusText}",
'body' => "Hello {$user['name']}! Your request was {$statusText}.",
]);
}
$messaging = (new Factory())
->withServiceAccount($serviceAccount)
->createMessaging();
$sendReport = $messaging->sendAll($messages);
echo 'Successful sends: '.$sendReport->successes()->count().PHP_EOL;
echo 'Failed sends: '.$sendReport->failures()->count().PHP_EOL;
I hope this helps!
I use this: https://telegram-bot-sdk.readme.io/docs
$response = $telegram->sendMessage([
'chat_id' => '#username',
'text' => 'Hello World'
]);
when the username is true, it works. but how can I handle errors? for example when username is wrong or not exist.
1-Some people does not have username!(you can have telegram account with just first name and valid phone number)
2-You cannot send to any valid username(Your bot can just send to users subscribed to your bot (open a chat at least once) and not blocked afterwards)
3-By telegram you can just send to users by chat_id( a large unique number) and not by #username .
I have a flash based ios app that I am currently testing on phone/ipod.
I have added push notification to the app and I am receiving device tokens from apple.
I have added those tokens to AWS SNS APN SandBox
The platform Application ARN looks like
arn:aws:sns:us-east-1:7860818154325:app/APNS_SANDBOX/gamename
I have added tokens to the PAA and they look like:
token: f63d05538cd7d9b86c76188dbfeb42edf26a1e23b47334a02a205e0fb54a812a
endpoint ARN: arn:aws:sns:us-east-1:7860818154325:endpoint/APNS_SANDBOX/gamename/7412740a-79e4-3b71-8e7f-56e127bc4cg1
Sending out the notification via PHP:
require 'vendor/autoload.php';
$sns = Aws\Sns\SnsClient::factory(array(
'key' => 'mykey',
'secret' => 'mysecret',
'region' => 'us-east-1'
));
$snsmessage = $sns->publish(array(
'TargetArn' => "$endpoint",
'Message' => 'A game is waiting for you to play'
));
(where $endpoint = "arn:aws:sns:us-east-1:7860818154325:endpoint/APNS_SANDBOX/gamename/7412740a-79e4-3b71-8e7f-56e127bc4cg1")
$snsmessage returns a message ID, so it looks like it is sending the message.
However no message is ever received on the phone.
I have tried manually sending a message from the SNS portal and the same issue. IT sends with no error message but it never arrives.
I am building the app as "device testing" and I am using provisionprofile that has push notifcation enabled.
I am not sure where to start looking to find the issue.
Any help would be appreciated.