There
I'm Using Twillio Example api
// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php,
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "ACea465f2e60ae87332cf47adb0e4aad64";
$AuthToken = "your_auth_token";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+15558675309" => "Curious George",
"+15558675308" => "Boots",
"+15558675307" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
"+15017250604",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
and here is my code
// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php,
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "accountsid";
$AuthToken = "authtoken";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"my-number-goes-here" => "Ali M. Ayad",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
"+13862593325",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey Ali This is test message form the api"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
when i put this code and i change the auth and id and the number is give my this message
Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'Authentication Error - invalid username' in C:\AppServ\www\tw\Services\Twilio.php:297 Stack trace: #0 C:\AppServ\www\tw\Services\Twilio.php(180): Base_Services_Twilio->_processResponse(Array) #1 C:\AppServ\www\tw\Services\Twilio\ListResource.php(92): Base_Services_Twilio->createData('/2010-04-01/Acc...', Array) #2 C:\AppServ\www\tw\Services\Twilio\Rest\Messages.php(24): Services_Twilio_ListResource->_create(Array) #3 C:\AppServ\www\tw\Services\Twilio\Rest\Messages.php(71): Services_Twilio_Rest_Messages->create(Array) #4 C:\AppServ\www\tw\sendnotifications.php(48): Services_Twilio_Rest_Messages->sendMessage('+13862593325', '+201063378955', 'Hey Ali This is...') #5 {main} thrown in C:\AppServ\www\tw\Services\Twilio.php on line 297
i'm using appserv
As the error message says (almost) clearly:
Authentication Error - invalid username
Assuming you are already registered at twilio; make sure you correctly defined your username and token in the real code you use:
Re-check again and again your username (and AuthToken also) for possible encoding issues and/or mistakes involving:
Correctly matching character case,
Trailing spaces, and
Special characters.
Also verify that your account is still valid at twilio.
"Authentication Error - invalid username'"
Your AccountSid and AuthToken are the "master keys" to your account. To authenticate using these "master keys," use HTTP basic auth with the username set to your AccountSid and the password set to your AuthToken. Your AccountSid and AuthToken can be found on your Account Dashboard.
Related
I am currently trying to implement what should be a simple task and send a message to one and / or more users via Moodle.
In the process I found 2 guides, which confused me at first.
Messaging 2.0 and Message API. Both have some differences and I didn't understand if my plugin needs to register as a Message Producer or not.
Unfortunately, I just can't get my message to be sent. I logged in with the user and checked the mailbox, no message there. Any help is appreciated.
What I did:
Created message.php within my db - folder and inserted the following code:
<?php
defined('MOODLE_INTERNAL') || die();
$messageproviders = array (
'datenotification' => array (
)
);
After that I expanded my language file with this:
$string['messageprovider:datenotification'] = 'Reminder for a presentation';
Like the guide advised, I updated my plugin to insert my messageprovider in the table mdl_message_providers. Finally, I implemented the actual sending of the message.
$eventdata = new \core\message\message();
$eventdata->component = 'local_reminder'; // the component sending the message. Along with name this must exist in the table message_providers
$eventdata->name = 'datenotification'; // type of message from that module (as module defines it). Along with component this must exist in the table message_providers
$eventdata->userfrom = core_user::get_noreply_user(); // user object , no-reply
$eventdata->userto = $user; // user object from database
$eventdata->subject = 'Test message';
$eventdata->fullmessage = 'This is my test message';
$eventdata->fullmessageformat = FORMAT_PLAIN; // text format
$eventdata->fullmessagehtml = '<p>This is my test message</p>';
$eventdata->smallmessage = '';
$eventdata->courseid = $course_id; // This is required in recent versions, use it from 3.2 on https://tracker.moodle.org/browse/MDL-47162
$result = message_send($eventdata);
Debugging:
var_dump($eventdata); //-> All data is included
var_dump($result); // returns int(5), id of message, no error
Adding the comment as an answer for future reference
Check if the message is installed and enabled via site admin > messaging > notification settings or direct to yoursite/admin/message.php
This is code of my bot in PHP, but it doesnt answer. What should I do? Here's the PHP error log :
[24-Sep-2018 09:06:29 UTC] PHP Warning: file_get_contents(https://api.telegram.org/bot694EMvJayx1zD-J3FPyKPfRlGka0 /sendMessage?chat_id=110***01&text=hellhAkbarixyzhMohammad Hosein): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in /home/xcqcctmm/public_html/BOT/getnewsir.php on line 22
The code is :
<?php
$token = '692******1zD-J3FPyKPfRlGka0';
// read incoming info and grab the chatID
$json = file_get_contents('php://input');
$telegram = urldecode ($json);
$results = json_decode($telegram);
$message = $results->message;
$text = $message->text;
$chat = $message->chat;
$user_id = $chat->id;
$username = $chat->username;
$first_name = $chat->first_name;
//send reply
$answer = "hello".$user_id . "h" . $username . "h" . $first_name;
$url = 'https://api.telegram.org/bot'.$token.'/sendMessage?chat_id='. $user_id .'&text='.$answer;
file_get_contents($url);
?>
it doesn't work.
Telegram's API returns 400 Bad Request, which could be caused by any of the following:
FIRSTNAME_INVALID: The first name is invalid
LASTNAME_INVALID: The last name is invalid
PHONE_NUMBER_INVALID: The phone number is invalid
PHONE_CODE_HASH_EMPTY: phone_code_hash is missing
PHONE_CODE_EMPTY: phone_code is missing
PHONE_CODE_EXPIRED: The confirmation code has expired
API_ID_INVALID: The api_id/api_hash combination is invalid
PHONE_NUMBER_OCCUPIED: The phone number is already in use
PHONE_NUMBER_UNOCCUPIED: The phone number is not yet being used
USERS_TOO_FEW: Not enough users (to create a chat, for example)
USERS_TOO_MUCH: The maximum number of users has been exceeded (to create a chat, for example)
TYPE_CONSTRUCTOR_INVALID: The type constructor is invalid
FILE_PART_INVALID: The file part number is invalid
FILE_PARTS_INVALID: The number of file parts is invalid
FILE_PART_Х_MISSING: Part X (where X is a number) of the file is missing from storage
MD5_CHECKSUM_INVALID: The MD5 checksums do not match
PHOTO_INVALID_DIMENSIONS: The photo dimensions are invalid
FIELD_NAME_INVALID: The field with the name FIELD_NAME is invalid
FIELD_NAME_EMPTY: The field with the name FIELD_NAME is missing
MSG_WAIT_FAILED: A waiting call returned an error
Unfortunately, you have to debug which one causing the actual error.
Source
I hope you can help me with an issue with phone call dialings using Plivo PHP (new SDK 4.0). First I will indicate what I want to achieve:
- A client on my website wants to talk with an agent of main, so he introduces his telephone number in a form, choose an agent, and finally when submit, the website connect both of them dialing (this works). But then, (here begin my problems), I can't retrieve the call details (status, duration, initial and end dates of the call, etc...) for invoicing the client according to some of these details.
Edited 2018/02/23:
Ramya, the 600 error has dissapeared and everything seems to be ok as I see in the Plivo debug log. Below are my new codes (I think better done thanks to your instructions), and then, I show you the Plivo debud log (perhaps it's better you can see it inside my account, call made Feb 23, 2018 18:33:15), and finally I see my server debug error log is empty!.
The main problem is that dialstatus.php file, although seems to receive the parameters, I don't know how to access them because dialstatus.php does not execute showing the data in my monitor (in my code for example, this line never shows in the monitor screen:)
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
So even though it receives the parameters, I can not access them to manipulate them, print them on the screen, do ifs with them, etc. May it be perhaps a permission problem with the files? (These php files have 6,4,4 permissions on my server, the same as the others).
Thank you!
Code 1: makecall.php
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("**********", "**************************");
$telefono_cliente = "34*******";
$telefono_experto = "34*********";
$duracion = 50;
try {
$response = $client->calls->create(
"3491111111",
[$telefono_experto],
"https://www.ejemplo.com/llamar/response.php?telf=$telefono_cliente",
'POST',
[
'time_limit' => $duracion,
]
);
$id = $response->requestUuid;
echo "<br>Este es el requestUuid: " . $id . "<br><br>";
}
catch (PlivoRestException $ex) {
print_r($ex);
}
?>
Code 2: response.php
require 'vendor/autoload.php';
use Plivo\XML\Response;
$resp = new Response();
$params = array(
'callerId' => '3491111111',
'action' => "https://www.ejemplo.com/llamar/dialstatus.php",
'method' => "POST",
'redirect' => "false"
);
$body3 = 'Desde ejemplo un cliente desea hablar con usted.';
$params3 = array(
'language' => "es-ES", # Language used to read out the text.
'voice' => "WOMAN" # The tone to be used for reading out the text.
);
$resp->addSpeak($body3,$params3);
$dial = $resp->addDial($params);
//$number = "34**********";
$number = $_GET['telf'];
$dial->addNumber($number);
Header('Content-type: text/xml');
echo($resp->toXML());
/*
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Speak language="es-ES" voice="WOMAN">Desde ejemplo un cliente desea hablar con usted.</Speak>
<Dial redirect="false" method="POST" action="http://www.ejemplo.com/llamar/dialstatus.php" callerId="3491111111">
<Number>34********</Number>
</Dial>
</Response>
*/
?>
Code 3: dialstatus.php
// Print the Dial Details
$estado = $_REQUEST['DialStatus'];
$aleg = $_REQUEST['DialALegUUID'];
$bleg = $_REQUEST['DialBLegUUID'];
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
?>
Plivo Sales Engineer here.
Redirect = true is used only when you want to continue the call by returning another XML in your action URL. For you use case, you don't have to use this parameter. Even if the Redirect is set to false, Plivo will make a request to the action URL with a list of parameters. I looked into your account (here) and I can see this request getting sent with DialStatus, ALegUUID, BLegUUID along with other parameters.
Dial Action URL is the best place to know the DialStatus and DialHangupCause.
You can find the call duration and billing amount in Hangup URL request as well. This Hangup URL can be configured in your first API call (to the expert). By default, hangup URL is set to Answer URL.
Please raise a support ticket with us for further assistance.
I am trying to test the twilio sms reminder library with a trial account I created for this purpose. The problem is that when I launch the file from my XAMPP "webroot" folder that also contains the "Twilio" folder I see nothing, just a blank page on Mozilla Firefox while on IE the error code 500 is up. Please find my code below thank you.
<?php
require $_SERVER['DOCUMENT_ROOT']."/openemr/twilio/Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+14158675309" => "Curious George",
"+14158675310" => "Boots",
"+14158675311" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"+12057198157",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
I'm trying to work with the examples on the Twitter dev site but can't seem to get to the same signature as they have.
I am trying to complete step 3 on https://dev.twitter.com/docs/auth/implementing-sign-twitter because I am getting an error "Invalid or expired token" but I know it isn't because I've only just been given it, so it must be something wrong with my data packet.
The code I am using to try and generate this is:
// testing bit
$oauth = array(
'oauth_consumer_key'=>'cChZNFj6T5R0TigYB9yd1w',
'oauth_nonce'=>'a9900fe68e2573b27a37f10fbad6a755',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_timestamp'=>'1318467427',
'oauth_token'=>'NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0',
'oauth_version'=>'1.0'
);
$this->o_secret = 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
$this->c_secret = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw';
ksort($oauth);
$string = rawurlencode(http_build_query($oauth));
$new_string = strtoupper($http_method).'&'.rawurlencode($main_url[0]).'&'.$string;
// The request_token request doesn't need a o_secret because it doesn't have one!
$sign_key = strstr($fullurl,'request_token') ? $this->c_secret.'&' : $this->c_secret.'&'.$this->o_secret;
echo urlencode(base64_encode(hash_hmac('sha1',$new_string,$sign_key,true)));exit;
And I'm assuming that the keys listed on this page are in fact correct: https://dev.twitter.com/docs/auth/creating-signature. So in that case the signature should be 39cipBtIOHEEnybAR4sATQTpl2I%3D.
If you can spot what I'm missing that would be great.
Your consumer secret and token secret are incorrect for the page you reference. If you look further up the page you can see that they should be:
Consumer secret: L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg
Token secret: veNRnAWe6inFuo8o2u8SLLZLjolYDmDP7SzL0YfYI
Also in Step 3 you need to include the oauth_verifier in the list of parameters when calculating your signature base string.
I'm not familiar with PHP so I haven't checked your code to calculate the signature.
This code has now worked - I will tidy it up from there :)
// This function is to help work out step 3 in the process and why it is failing
public function testSignature(){
// testing bit
$oauth = array(
'oauth_consumer_key'=>'cChZNFj6T5R0TigYB9yd1w',
'oauth_nonce'=>'a9900fe68e2573b27a37f10fbad6a755',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_timestamp'=>'1318467427',
'oauth_token'=>'NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0',
'oauth_version'=>'1.0'
);
$this->o_secret = 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
$this->c_secret = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw';
ksort($oauth);
$string = http_build_query($oauth);
$new_string = strtoupper($http_method).'&'.$main_url[0].'&'.$string;
$new_string = 'POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521';
// The request_token request doesn't need a o_secret because it doesn't have one!
$sign_key = $this->c_secret.'&'.$this->o_secret;
echo 'Should be: tnnArxj06cWHq44gCs1OSKk/jLY=<br>';
echo 'We get: '.base64_encode(hash_hmac('sha1',$new_string,$sign_key,true));
exit;
}
you want to access token from twitter and sign in implementation you can see in this example.
1) http://www.codexworld.com/login-with-twitter-using-php/
and this one for timeline tweets
2) http://www.codexworld.com/create-custom-twitter-widget-using-php/
may be this help you .