How to create persistent rooms in openfire using strophe? - xmpp

I'm using the following iq message to create persistent rooms in openfire:
var configiq = $iq({
to : chatObj.getActiveChatRoomName() + "#" + chatObj.groupChatService,
type : "set"
}).c("x", {
xmlns : "jabber:x:data",
type : "submit"
}).c('field', {
"var" : "FORM_TYPE"
})
.c('value').t("http://jabber.org/protocol/muc#roomconfig")
.up().up()
.c('field', {
"var" : "muc#roomconfig_persistentroom"
})
.c('value').t("1");
chatObj.connection.sendIQ(configiq.tree(), function () {
console.log('success');
}, function (err) {
console.log('error', err);
});
But, I am getting the following error:
error <iq xmlns=​"jabber:​client" type=​"error" id=​"1356:​sendIQ" from=​"msrtc0711#conference.stslp239" to=​"ashishjmeshram#stslp239/​ax8nb2atg1">​<x xmlns=​"jabber:​x:​data" type=​"submit">​…​</x>​<error code=​"400" type=​"modify">​<bad-request xmlns=​"urn:​ietf:​params:​xml:​ns:​xmpp-stanzas">​</bad-request>​</error>​</iq>​

Using the Strophe.muc plugin is easier:
1) firstly join the room (this creates an instant room):
connection.muc.join(room_jid, nick);
2) then create a "configured room", eventually with a subject and a description associated:
var config = {"muc#roomconfig_publicroom": "1", "muc#roomconfig_persistentroom": "1"};
if (descr) config["muc#roomconfig_roomdesc"] = descr;
if (subject) config["muc#roomconfig_subject"] = subject;
connection.muc.createConfiguredRoom(room_jid, config, onCreateRoomSuccess, onCreateRoomError);
A working example is available here: http://plnkr.co/edit/Mbi15HDZ2yW5vXskS2X6?p=preview

Related

Create a document using CMIS in Javascript

I am trying to create a document in the SAP Document Center of HCP using Javascript and I can not. SAP Document Center uses the CMIS protocol for communication with other applications. I have been able to connect from my SAPUI5 application with the SAP Document Center. I have also managed to create a folder as follows:
createFolder: function(repositoryId, parentFolderId, folderName) {
var data = {
objectId: parentFolderId,
cmisaction: "createFolder",
"propertyId[0]": "cmis:name",
"propertyValue[0]": folderName,
"propertyId[1]": "cmis:objectTypeId",
"propertyValue[1]": "cmis:folder"
};
$.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
type: "POST",
data: data
}).done(function() {
MessageBox.show("Folder with name " + folderName + " successfully created.");
}).fail(function(jqXHR) {
MessageBox.show("Creation of folder with name " + folderName + " failed. XHR response message: " + jqXHR.responseJSON.message);
});
},
However, I find it impossible to create a document. I can not find an internet sample for the CMIS "createDocument" method. There are many examples for Java but nothing to do with Javascript. I do not know what the structure of the data to send. The code is as follows:
createDocument: function(repositoryId, parentFolderId, documentName, content) {
/**
* 'content' contains the whole document converted to a base64 string like this:
* "data:application/pdf;base64,JVBERi0xLjUNJeLjz9MNCjIxNCAwIG9iag08P..."
*/
var data = {
objectId: parentFolderId,
cmisaction: "createDocument",
contentStream: content,
"propertyId[0]": "cmis:name",
"propertyValue[0]": documentName,
"propertyId[1]": "cmis:objectTypeId",
"propertyValue[1]": "cmis:document"
};
$.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
type: "POST",
data: data
}).done(function() {
MessageBox.show("Document with name " + documentName + " successfully created.");
}).fail(function(jqXHR) {
MessageBox.show("Creation of document with name " + documentName + " failed. XHR response message: " + jqXHR.responseJSON.message);
});
},
With this I create a file record within the SAP Document Center but it does not take the data. An unformatted file is created, when it should have the format sent (PDF, txt, Excel, Doc, ...).
Does anyone know how to do it?
Regards.
Links of interest:
CMIS Standard
http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-1710002
Usage examples for Java (not Javascript)
http://chemistry.apache.org/java/developing/guide.html
I have been through a similar problem. My solution is to change it from base64 to a FormData approach, so I got the file input value instead of the content base64 string. It worked fine.
this.createObject = function (fileInput, objectName,folderId, cbOk, cbError) {
if (!folderId) {
folderId = _this.metadata.rootFolderId;
}
var documentData = {
'propertyId[1]': 'cmis:objectTypeId',
'propertyValue[1]': 'cmis:document',
'propertyId[0]': 'cmis:name',
'propertyValue[0]': objectName,
'objectId': folderId,
'cmisaction': 'createDocument',
'content' : fileInput
};
var formData = new FormData();
jQuery.each(documentData, function(key, value){
formData.append(key, value);
});
$.ajax({
url: _this.metadata.actionsUrl,
data: formData,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
cbOk(data);
},
error: function(err){
cbError(err);
}
});
};
In the view.xml add following lines.
<FileUploader id="fileUploader"
name="myFileUpload"
uploadUrl="/cmis/root"
width="400px"
tooltip="Upload your file to the local server"
uploadComplete="handleUploadComplete"
change='onChangeDoc'/>
the upload url will be url to the neo destination. In the neo.app.json add the following lines.
{
"path": "/cmis",
"target": {
"type": "destination",
"name": "documentservice"
},
"description": "documentservice"
}
In the controller.js add the following lines of code.
if (!oFileUploader.getValue()) {
sap.m.MessageToast.show("Choose a file first");
return;
}
var data = {
'propertyId[0]': 'cmis:objectTypeId',
'propertyValue[0]': 'cmis:document',
'propertyId[1]': 'cmis:name',
'propertyValue[1]': file.name,
'cmisaction': 'createDocument'
};
var formData = new FormData();
formData.append('datafile', new Blob([file]));
jQuery.each(data, function(key, value) {
formData.append(key, value);
});
$.ajax('/cmis/root', {
type: 'POST',
data: formData,
cache: false,
processData: false,
contentType: false,
success: function(response) {
sap.m.MessageToast.show("File Uploaded Successfully");
}.bind(this),
error: function(error) {
sap.m.MessageBox.error("File Uploaded Unsuccessfully. Save is not possible. " + error.responseJSON.message);
}
});
In the neo cloud, maintain the url for following configuration in destination tab. https://testdaasi328160trial.hanatrial.ondemand.com/TestDaaS/cmis/json/repo-id
repo-id will be your repository key.
this will solve the problem. You will be able to upload and the document.

Twilio IP Messaging user not found

I'm trying to add a users identity to a channel using the REST API using instructions here: https://www.twilio.com/docs/api/ip-messaging/rest/members#action-create
I'm posting to the /Channels/channelId/Members endpoint - I'm certain my request is structured correctly.
I get an error back from Twilio IP Messaging saying:
{"code": 50200, "message": "User not found", "more_info": "https://www.twilio.com/docs/errors/50200", "status": 400}
My understanding was that we can provide our own identity when we want to add someone to a Channel. How can I 'register' the user (with an email) before adding them to the Channel?
EDIT - The code:
var _getRequestBaseUrl = function() {
return 'https://' +
process.env.TWILIO_ACCOUNT_SID + ':' +
process.env.TWILIO_AUTH_TOKEN + '#' +
TWILIO_BASE + 'Services/' +
process.env.TWILIO_IPM_SERVICE_SID + '/';
};
var addMemberToChannel = function(memberIdentity, channelId) {
var options = {
url: _getRequestBaseUrl() + 'Channels/' + channelId + '/Members',
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
form: {
Identity: memberIdentity,
},
};
request(options, function(error, response, body) {
if (error) {
// Getting the error here
}
// do stuff with response.
});
};
addMemberToChannel('test1#example.com', <validChannelId>);
Twilio developer evangelist here.
In order to add a user to be a member of a channel, you do indeed need to register them first. Check out the documentation for creating a user in IP Messaging.
With your code you'd need a function like:
var createUser = function(memberIdentity) {
var options = {
url: _getRequestBaseUrl() + 'Users',
method:'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
form: {
Identity: memberIdentity,
}
};
request(options, function(error, response, body) {
if (error) {
// User couldn't be created
}
// do stuff with user.
});
}
Could I also suggest you take a look at the Twilio helper library for Node.js. It handles the creation of URLs like you're doing for you. The code looks cleaner too, you can create a user with the helper library like this:
var accountSid = 'ACCOUNT_SID';
var authToken = 'AUTH_TOKEN';
var IpMessagingClient = require('twilio').IpMessagingClient;
var client = new IpMessagingClient(accountSid, authToken);
var service = client.services('SERVICE_SID');
service.users.create({
identity: 'IDENTITY'
}).then(function(response) {
console.log(response);
}).fail(function(error) {
console.log(error);
});
Let me know if this helps at all.

Unable to set node label dynamically using the Neo4j REST API

Following the syntax proposed on the Neo4j REST API transactional page, I have tried running the request "CREATE (node:{group} { name: {name}}) RETURN node", { group: "Group", name: "Name"}.
The use of :{group} as a dynamic variable causes an error:
"Neo.ClientError.Statement.InvalidSyntax","message":"Invalid input '{': expected whitespace or a label name
Is this pilot error on my part, a bug in the Neo4j query parser, or a something that cannot be done?
Here's my Nodej.s code:
var request = require("request")
var host = 'localhost'
, port = 7474
, user = "neo4j"
, pass = "1234"
var uri = 'http://' + user + ":" + pass + "#" + host + ':' + port + '/db/data/transaction/commit'
function runCypherQuery(query, params, callback) {
request.post({
uri: uri,
json: {statements: [{statement: query, parameters: params}]}
},
function (err, res, body) {
callback(err, body)
})
}
runCypherQuery(
"CREATE (node:{group} { name: {name}}) RETURN node"
, { group: "Group"
, name: "Name"
}
, function (err, resp) {
if (err) {
console.log(err)
} else {
console.log(JSON.stringify(resp))
}
}
)
Node Labels cannot be parameterized in Cypher.
Try updating the label in the query as a string instead of passing a parameter:
"CREATE (node:" + group + " {name: {name}}) RETURN node"
Unfortunately, Cypher does not support parameterized label names.

OPA matcher for sap.m.MessageToast.show call?

How does a OPA match pattern for a sap.m.MessageToast.show call looks like?
I looked into the Code of sap.m.MessageToast.show and assumed the use control is sap.ui.core.Popup. Therefore I tried the following matcher:
iShouldSeeAToastMessage : function() {
return this.waitFor({
controlType : "sap.ui.core.Popup",
success : function (aDialog) {
ok(true, "Found a Toast: " + aDialog[0]);
},
errorMessage : "No Toast message detected!"
});
},
Is the controlType correct? How could the matcher section look like?
This should work:
return this.waitFor({
pollingInterval : 100,
viewName : "YOUR_VIEW_NAME_HERE",
check : function () {
return !!sap.ui.test.Opa5.getJQuery()(".sapMMessageToast").length;
},
success : function () {
ok(true, "Found a Toast");
},
errorMessage : "No Toast message detected!"
});

Parse - How to insert data on parse server using REST Api using javascript?

I am integrating parse rest api to insert data on a table using jsp page. and using following code in javascript -
var headers = {
"X-Parse-Application-Id" : "myparseappid",
"X-Parse-REST-API-Key" : "myparserestapi"
};
// Variable to store data:
var userData = {
"name" : "anyname"
};
var data = JSON.stringify(userData);
// Send data:
$.ajax({
type : "POST",
url : "https://api.parse.com/1/classes/MyClassName",
data : userData,
contentType : "application/json",
headers : headers,
dataType:"json",
success : function(data, status, xhr) {
alert("data:" + JSON.stringify(data) + " status: "+ status);
if (status === "success") {
// Show success feedback:
alert("Data was saved successfully");
} else {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
},
error : function(data, status, xhr) {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
});
and for ajax i called following js -
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
Question - It is not saving the records whats wrong with above code. please suggest me?
Thanks in advance!