How to Replace a text by calling Onlyoffice ApI - onlyoffice

I am using Onlyoffice document Server version 5.0.3 It works fine. find and replace a text in the document editor
Onlyoffice configuration
file: editor.jsp
config = {
"document": {
"fileType": "docx",
"key": "Khirz6zTPdfd7",
"title": "sample.docx",
"url": "http://192.168.0.1:8080/onlyofficeexample/files/192.168.0.1/sample.docx"
},
"documentType": "text",
"editorConfig": {
"callbackUrl": "http://192.168.0.1:8080/onlyofficeexample/IndexServlet?type=track&fileName=sample.docx&userAddress=192.168.0.1"
}
........
.......
};
var docEditor = new DocsAPI.DocEditor("placeholder", config);
setTimeout(function(){
var text_replace = {
textsearch: "~($#effective_date#$)~",
textreplace: "23/05/1991",
matchcase: false,
matchword: false,
highlight: true
};
docEditor.onReplaceText(text_replace);
}, 30000);
I am trying to replace a text with calling API, and have created the further trigger function in Onlyoffice API call.
//trigger function
onReplaceText: function (data) {
$me.trigger("onreplacetext", data)
},
here i want find and replace a text based on data passed to this function
onReplaceText:function(data){
}
Common.Gateway.on('onreplacetext',_.bind(me.onReplaceText, me));
thank you

It is incorrect to use the method of asc_replaceText to modify the content of the document. Your request can be realized by means of document builder (please see this section of API) or by means of plugin. We are also glad to announce that feature list of find-replace method will be added in the following update of the document builder and it will be also available for the plugin.

finally, i replaced the text in onlyoffice API by using below code.
//trigger function
onReplaceText: function (data) {
$me.trigger("onreplacetext", data)
},
here i want find and replace a text based on data passed to this function
onReplaceText:function(data){
data=data.data;
this.api.asc_replaceText(data.textsearch, data.textreplace,true, data.matchcase, data.matchword);
}
Common.Gateway.on('onreplacetext',_.bind(me.onReplaceText, me));

Related

(NodeJS) WordPress API, updating Events Calendar event (tribe event) removes featured image from post

I'm using the Wordpress API to update tribe events. The updates are successfully sent (and the change is made) but as a side-effect, any time I do it, the featured image is removed from the post...
wpapi package setup:
Because The Events Calendar has it's own routes that aren't built-in by default in the wpapi package, I use the wp.registerRoute function to set that up. I don't think there's a problem with the way I set that up because otherwise it works.
var WPAPI = require( 'wpapi' );
var wp = new WPAPI({
endpoint: 'https://www.example.com/wp-json',
username: 'username',
password: 'mypassword'
});
wp.tribeevent = wp.registerRoute('tribe/events/v1', '/events/(?P<id>)');
example update:
function showEvent (post_id) {
let data = { "hide_from_listings" : false }
wp.tribeevent().id(post_id).update(data)
}
Haven't been able to find anyone with this issue online, so I'm posting here after exhausting myself trying to get it to work without removing the image... Am I doing this wrong? Is this just a bug? Any suggested workarounds?
I've also tried adding the existing image info into the update data sent, but I get this response when doing so:
{
"error": {
"code": "rest_invalid_param",
"message": "Invalid parameter(s): image",
"data": {
"status": 400,
"params": {
"image": "Invalid parameter."
},
"details": []
}
}
}
Otherwise, when making an update such as { "hide_from_listings" : false }, when the json response comes back, the value of the image key just comes back as false: { "image" : false }
Would greatly appreciate any kind of input on this issue...

postback button in dialogflow messenger cx

Hello I'm trying to create a flow in dialogflow cx, where in case of multiple options I want my user to select 1 option where all the options are buttons.
I have used the default payload but not sure how can I send back which button got clicked to my webhook and return respective info, currently if I click on button it simply open example.com, if I exclude the link it opens same page in new tab.
{
"type": "button",
"icon": {
"type": "chevron_right",
"color": "#FF9800"
},
"text": "Button text 1",
"link" : "www.example.com",
"event": {
"name": "some name",
"languageCode": "en",
"parameters": {}
}
}
For your use case, since the button response type always redirects to a page when clicked, you can consider using suggestion chips instead.
{
"richContent": [
[
{
"options": [
{
"text": "Chip 1"
},
{
"text": "Chip 2"
}
],
"type": "chips"
}
]
]
}
Suggestion chips act like a user text query when the user clicks on it, therefore, you can just create a route that can be triggered by text of the chip and get the text query from the webhook request sent to your webhook to return the respective information. For example:
Intent:
Route:
Then in your webhook, you can get the parameter value in the text field of the webhook request which you will refer to in order to create a webhook response with the respective information.
Here’s an example in Node.js using Express:
app.post("/webhook", (req, res) => {
let option = req.body.text;
let jsonResponse = {
fulfillment_response: {
messages: [
{
text: {
//fulfillment text response to be sent to the agent
text: [`You've chosen the ${option} option`]
}
}
]
}
};
res.json(jsonResponse);
});
Alternatively, you can also use entity types and assign the selected chip into a parameter that will be also sent to your webhook.
To assign the text of the chip to a parameter, the intent of the route should contain training phrases that are annotated to an entity type containing all of the options. For example:
Intent:
Entity Type:
Then in your webhook, you can get the parameter value in the intentInfo.parameters.parameter_id.resolvedValue field of the webhook request which you will refer to in order to create a webhook response with the respective information.
Here’s an example in Node.js using Express:
app.post("/webhook", (req, res) => {
let option = req.body.intentInfo.parameters.options.resolvedValue;
let jsonResponse = {
fulfillment_response: {
messages: [
{
text: {
//fulfillment text response to be sent to the agent
text: [`You've chosen the ${option} option`]
}
}
]
}
};
res.json(jsonResponse);
});
Results:
There is a simple albeit hacky way I have discover possible (tested in es). Which is to make a chip and get its element then force clicking it
We can listen to button click and I detect that it was empty button with just text. Then I use renderCustomCard to make a chip. Everything inside dialogflow messenger are hidden deep inside nested shadowRoot. But as of now its structure allow us to get the chip out to call click() on it. In effect it make it seem very the same as user manually click the chip
const dfMessenger = document.querySelector('df-messenger');
dfMessenger.addEventListener('df-button-clicked',function(event) {
if(event.detail.element.event || event.detail.element.link)
return;
dfMessenger.renderCustomCard([
{
"type": "chips",
"options": [
{
"text": event.detail.element.text
}
]
}
]);
var messageList = dfMessenger.shadowRoot.querySelector("df-messenger-chat").shadowRoot.querySelector("df-message-list").shadowRoot;
var chips = [...messageList.querySelectorAll("df-chips")].flatMap((chips) => [...chips.shadowRoot.querySelectorAll(".df-chips-wrapper>a")]).filter((a) => a.innerHTML.indexOf(event.detail.element.text) > -1);
if(chips.length > 0)
chips.slice(-1)[0].click();
});
Working for today. No guarantee they will block this method in the future. But I actually guess they would implement actual postback button in similar manner later after beta version

IBM Bluemix Discovery - query parameter

I have created a Discovery service on my bluemix account. I want to query my documents from a nodejs application.
I have built a query with some aggregation, tested it using the bluemix online tool and it's working well.
Now when I query the collection from my code, whatever my parameters are, I always receive all of my documents with the enriched text and so on. I think I am missing how to send the query attributes to the service (like filters and aggregations).
Here is my code:
var queryParams = {
query:'CHLOE RICHARDS',
return:'title',
count:1,
aggregations:'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)'
};
discovery.query({environment_id:that.environment_id, collection_id:that.collection_id, query_options:queryParams }, function(error, data) {
if(error){
console.error(error);
reject(error);
}
else{
console.log(JSON.stringify(data, null, 2));
resolve(data.matching_results);
}
});
And the result is always:
{
"matching_results": 28,
"results": [
{
"id": "fe5e2a38e6cccfbd97dbdd0c33c9c8fd",
"score": 1,
"extracted_metadata": {
"publicationdate": "2016-01-05",
"sha1": "28434b0a7e2a94dd62cabe9b5a82e98766584dd412",
"author": "Richardson, Heather S",
"filename": "whatever.docx",
"file_type": "word",
"title": "no title"
},
"text": "......
Independantly of the value of the query_optionparameter. Can you help me?
EDIT
Instead of the query_options:queryParams, I have used query:"text:CHLOE RICHARDS" and it's working well. Now my problem still remains to find the right parameter format to add the aggregations I want
EDIT 2
So I have looked at IBM's example on Github more carefully, and the parameters are now formatted like this:
const queryParams = {
count: 5,
return: 'title,enrichedTitle.text',
query: '"CHLOE RICHARDS"',
aggregations: [ 'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)' ],
environment_id: '1111111111',
collection_id: '11111111111'
};
It works well if I use only the query attribute. Now if I only use the aggregations one, all the documents are sent back as a result (which is understandable) but I have no aggregation part, so I can not access the list of proper name in my documents.
Your query does not look right. I you are going to use query then you will need to construct a query search like text:"CHLOE RICHARDS"
If you want to perform a natural language query then you should be setting the parameter natural_language_query.

error in filtered function creation on couchdb

I'm trying to follow this tutorial to filter the replication between a pouchdb and a couchdb databases
https://pouchdb.com/2015/04/05/filtered-replication.html
The problem is when I try to create the filtered function in the Fauxton webapp. In my created database, I click Design Document > New Docs and then paste the function:
{
"_id": "_design/app",
"filters": {
"by_agent": function(doc, req) {
return doc.agent === req.query.agent;
}.toString()
}
}
and when I click Create Document button, it crashes. The javascript console says
Uncaught SyntaxError: Unexpected token u in JSON at position 61
at JSON.parse ()
at t.checkDocIsValid (https://127.0.0.1:6984/_utils/dashboard.assets/js/bundle-b8e0ba71119195edb7ec64b98f53d9b9.js:529:19481)
at t.saveDoc (https://127.0.0.1:6984/_utils/dashboard.assets/js/bundle-b8e0ba71119195edb7ec64b98f53d9b9.js:529:19056)
...
how do I create the filtered function in couchDB? Maybe that isn't the procedure or I have to create it on another dababase. Thanks in advance
So what you're trying to do is use JavaScript code to create a view. Therefore, Fauxton takes only JSON as a document.
Here's how you can get the JSON from the JavaScript snippet :
//The snippet you had was a JavaScript object
//Even if it seems like a JSON object, there is a function() declaration followed by a .toString()
//By doing so, it easier to write functions instead of writing them in a raw string.
var javascriptObject = {
"_id": "_design/app",
"filters": {
"by_agent": function(doc, req) {
return doc.agent === req.query.agent;
}.toString()
}
}
console.info("You should use the following string in your Fauxton Editor:");
console.log(JSON.stringify(javascriptObject));
You should use the following string instead of the JavaScript snippet you tried:
{
"_id": "_design/app",
"filters": {
"by_agent": "function (doc, req) {\n return doc.agent === req.query.agent;\n }"
}
}

node-elastic full document update

In my nodejs elastic writer I want to replace one document with another.
Currently, I run-
var data = { doc: doc, "doc_as_upsert": true };
var metadata =
{ update: { _id: idToUpdate, _index:indexName,_type: INDEX_TYPE_PREFIX } };
body.push(metadata);
body.push(payment);
}
elasticsearchClient.bulk({
body: body,
}, function (err, resp) {
But in case the document in elastic contained field X and the updated document didn't, field X stays in elastic- I want it to be removed.
According to
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
using "doc:" is for partial update, so what's the alternative for full update?
Don't use the update api, use the index api instead.

Resources