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
Related
Sorry this may be a trivial question but I am new to PHP. In the documentation to retrieve project tasks, the following code is provided to connect to an Active Collab cloud account:
<?php
require_once '/path/to/vendor/autoload.php';
// Provide name of your company, name of the app that you are developing, your email address and password.
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you#acmeinc.com', 'hard to guess, easy to remember');
// Show all Active Collab 5 and up account that this user has access to.
print_r($authenticator->getAccounts());
// Show user details (first name, last name and avatar URL).
print_r($authenticator->getUser());
// Issue a token for account #123456789.
$token = $authenticator->issueToken(123456789);
// Did we get it?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
print $token->getUrl() . "\n";
print $token->getToken() . "\n";
} else {
print "Invalid response\n";
die();
}
This works fine. I can then create a client to make API calls:
$client = new \ActiveCollab\SDK\Client($token);
and get the list of tasks for a given project as shown in the documentation.
$client->get('projects/65/tasks'); // PHP object
My question is, what methods/attributes are available to get the list of tasks? I can print the object using print_r() (print will obviously not work), and what I really want is in the raw_response header. This is private however and I cannot access it. How do I actually get the list of tasks (ex: the raw_response either has a string or json object)?
Thanks in advance.
There are several methods to work with body:
$response = $client->get('projects/65/tasks');
// Will output raw JSON, as string.
$response->getBody();
// Will output parsed JSON, as associative array.
print_r($response->getJson());
For full list of available response methods, please check ResponseInterface.
If you wish to loop through tasks, use something like this:
$response = $client->get('projects/65/tasks');
$parsed_json = $response->getJson();
if (!empty($parsed_json['tasks'])) {
foreach ($parsed_json['tasks'] as $task) {
print $task['name'] . "\n"
}
}
Good day, I would like to create a menu for my ussd app, it's my first app so i'm still a little bit confused.
The only i was able to do so far is to display message on the screen that says "Welcome dear customer", but me I want to create an interactive menu.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
header("Content-type: text/xml; charset=utf-8");
/**
* Here we receive the xml from the network company
*
*/
$json = file_get_contents('php://input');
$json_data = json_decode($json);
error_log($json_data->param1);
$xml = simplexml_load_string($json_data->param1) or die('Error:
Cannot create the object');
$MessageType = $xml->MessageType;
$ConversationID = $xml->ConversationID;
$SessionID = $xml->SessionID;
$TransactionID = $xml->TransactionID;
$MessageString = $xml->MessageString;
$MSISDN = $xml->MSISDN;
$Success = $xml->Success;
$IsFinal = $xml->IsFinal;
$DateTimeReceived = $xml->DateTimeReceived;
$MNO = $xml->MNO;
/**
*Here we create a xml that will send a message to the user
*
*
*/
$option1 ='1.Welcome dear customer';
$xml = new SimpleXMLElement('<UssdMessage/>');
$xml->addChild('MessageType', $MessageType);
$xml->addChild('ConversationID', $ConversationID);
$xml->addChild('SessionID', $SessionID);
$xml->addChild('TransactionID', $TransactionID);
$xml->addChild('MessageString', $option1);
$xml->addChild('MSISDN', $MSISDN);
$xml->addChild('Success', 'true');
$xml->addChild('IsFinal', 'TRUE');
$xml->addChild('DateTimeReceived', $DateTimeReceived);
$xml->addChild('MNO', $MNO);
echo $xml->asXML();
The platform that converts the XML to SMPP must return some type of session indicator and with the MSISDN of the subscriber you can respond to the options that the user has selected.
We implement a finite state machine to support the logic of the menu.
Each operation is a state and in its definition you link to the next state in case of transition OK or in case of transition ERROR you respond a message to the user.
Within the SMPP protocol, the ussd_service_op parameter is usually used to determine if the response sent allows the user to respond or is a response that ends a user session.
The provider of the platform should give you the documentation referring to the bidirectional sessions and there should be the values for ussd_service_op.
I leave the link to the documentation of the SMPP protocol, you should read about submit_sm and deliver_sm http://docs.nimta.com/SMPP_v3_4_Issue1_2.pdf.
Sorry for my foreign english
I have been searching for days for a working example! The Netsuite documentation is really poor. I don't know what exactly are the config parameters or where I can get them.
I'm recreating the get_customer example.
My code:
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = "21";
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
if (!$getResponse->readResponse->status->isSuccess) {
echo "GET ERROR";
} else {
$customer = $getResponse->readResponse->record;
echo "GET SUCCESS, customer:";
echo "\nCompany name: ". $customer->companyName;
echo "\nInternal Id: ". $customer->internalId;
echo "\nEmail: ". $customer->email;
}
?>
This is the thrown error:
Webservice host must be specified in NSPHPClient->__construct()
How can I fix this?
To be clear, there should be a file in the same directory as NetSuiteService.php called NSconfig.php. You don't need to include this file in your script; it gets called from NSPHPClient.php. The default NSconfig.php looks like this:
$nsendpoint = "2013_2";
$nshost = "https://webservices.netsuite.com";
$nsemail = "jDoe#netsuite.com";
$nspassword = "mySecretPwd";
$nsrole = "3";
$nsaccount = "MYACCT1";
The nsendpoint and nshost should stay as they are.
The tricky part is getting the correct settings for the other variables. First off, you need to Set up Web Services (http://www.netsuite.com/portal/partners/integration/download/SuiteTalkWebServicesPlatformGuide_2012.2.pdf Starting at page 34), then you need to create a Web Services Role (page 44), and make sure that Role has the necessary permissions. Assign that Role to a user that also has the appropriate permissions, then...
nsemail = the email of the user with the web services role
nspassword = the password of the nsemail user
nsrole = the internal role id of the web services role
nsaccount = your netsuite account number (most likely six digits)
(for info on seeing your internal role ids, see page 20 of the PDF above.)
Make sure that you have included the NSconfig.php file. Also you need to modify this file with your account credentials
I used php server side to connect with clickatell messages service , i used the soap api technique to make the connection . it is working .but in my code , i can send just one message at the same time , here is the code :
function actionSendSMS(){
$msgModel = new Messages();
$settModel = new Settings();
$setRows = $settModel->findAll();
$usr=$setRows[0]->clickatell_usr;
$pwdRows = $settModel->findAll();
$pwd=$pwdRows[0]->clickatell_pwd;
$api_idRows = $settModel->findAll();
$api_id=$api_idRows[0]->clickatell_api_id;
$msgModel->findAllBySql("select * from messages where is_sent=0 and
send_date=".date("m/d/Y"));
$client = new SoapClient("http://api.clickatell.com/soap/webservice.php?WSDL");
$params = array('api_id' => $api_id,'user'=> $usr,'password'=> $pwd);
$result = $client->auth($params['api_id'],$params['user'],$params['password']);
$sessionID = substr($result,3);
$callback=6;
// echo $result."<br/>";
// echo $sessionID;
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=>
$usr,'password'=>$pwd,
'to'=>array('962xxxxxxx'), 'from'=>"thetester",'text'=>'this is a sample test
message','callback'=>$callback);
$result2 = $client->sendmsg($params2['session_id'],
$params['api_id'],$params['user'],$params['password'],
$params2['to'],$params2['from'],$params2['text'],$params2['callback']);
print_r( $result2)."<br/>";
$apimsgid= substr($result2[0],4);
$rowsx=Messages::model()->findAllBySql("select * from messages where is_sent=0 and
send_date='".date("m/d/Y")."'");
for($i=0;$i<count($rowsx);$i++)
{
$rowsx[$i]->clickatell_id=$apimsgid;
$rowsx[$i]->save();
}
//echo $apimsgid."<br/>";
if (substr($result2[0], 0,3)==='ERR' && (!(substr($result2[0], 0,2)==='ID'
) ))
{
echo 'Connot Routing Message';
}
.... now you see that this code will send one message at the same time , forget about the id , its for personal purpose , now this service i have to modify it , to send multiple messages at the same time , and i will give every message an unique ID , so now my problem is : is there any one knows if there is a service to send multiple sms at the same time ;
as in my code i fill the information for one message ,but i need a service to send multiple sms , does any body can give me a link to this service , i made many searches but there is no answer i have found
Try startbatch command to send multiple messages at the same time (it also supports personalized). However, it is not based soap, it is based http api.
Have you tried
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx', '962xxxxxxx', '962xxxxxxx'), 'from'=>"thetester",'text'=...
or
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx,962xxxxxxx,962xxxxxxx'), 'from'=>"thetester",'text'=...
As part of a PHP webapp I have MySQL contacts table. It is integrated throughout the app, allowing you add a contact, edit a contact or add a contact as a relation to another table. However, currently it is self-contained. The company would like it to sync with Exchange, so that contacts added to Exchange will show up on the webapp and contacts added on the webapp will show up through Exchange.
So I have two problems: 1) communicating with Exchange 2) syncing with Exchange.
As far as the basic communication goes, it looks like this library will be able to manage it https://github.com/jamesiarmes/php-ews. However, I am quite lost as to how to manage syncing and don't where to start.
The build-in way to sync items is via function called SyncFolderItems. Basically to Exchange everything, including contacts is a folder, so you'll just pass CONTACTS as DistinguishedFolderId in your sync request.
The sync works by donloading all the items for given account in batches of max 512 elements and after each batch it gives you SyncState as a refernce point for Exchange to know where you left off. So it gives you ability to do incremental sync.
Now, that's one way of course, meaning Exchange -> Your DB. The other way it aeound you should preform atomic updates/request - the moment you change/add/delete item form your db you should issue adequate request to Exchange server to keep data in sync, elese it'll be overwritten on your next SyncFolderItems.
You can read up more on SyncFolderItems # MSDN
If you'd like to see example of SyncFolderItems you can take a look # python version of EWSWrapper, it's been added in recently. Although it's python, you can still get the basic idea how to construct the request / handle response.
Hope this helps :)
I am aware that this topic is pretty old. However, for future reference find a solution below. It is using the above-mentioned library php-ews.
I have also just added this to the official php-ews wiki: https://github.com/jamesiarmes/php-ews/wiki/Calendar:-Synchronization
// Define EWS
$ews = new ExchangeWebServices($host, $username, $password, $version);
// fill with string from last sync
$sync_state = null;
$request = new EWSType_SyncFolderItemsType;
$request->SyncState = $sync_state;
$request->MaxChangesReturned = 512;
$request->ItemShape = new EWSType_ItemResponseShapeType;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->SyncFolderId = new EWSType_NonEmptyArrayOfBaseFolderIdsType;
$request->SyncFolderId->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType;
$request->SyncFolderId->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$response = $ews->SyncFolderItems($request);
$sync_state = $response->ResponseMessages->SyncFolderItemsResponseMessage->SyncState;
$changes = $response->ResponseMessages->SyncFolderItemsResponseMessage->Changes;
// created events
if(property_exists($changes, 'Create')) {
foreach($changes->Create as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// updated events
if(property_exists($changes, 'Update')) {
foreach($changes->Update as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// deleted events
if(property_exists($changes, 'Delete')) {
foreach($changes->Delete as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}