How to have two timeline feeds for two separate groups and query separately - getstream-io

I'm trying to understand how Stream works, but I just don't get it... I have two feeds I want to create, they should be seperate from each other.
With the example below I thought that I'm first adding activities as Eric, I have one activity that goes just to Eric's feed, one that goes to the cpaentries feed and one that goes to the productcafe feed.
const ericToken = client.feed('timeline', 'eric').token
var ericFeed = client.feed('timeline', 'eric', ericToken);
// Add the activity to the feed
ericFeed.addActivity({
actor: 'eric',
tweet: 'Hello world',
verb: 'tweet',
object: 1
});
ericFeed.addActivity({
actor: 'eric',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet',
object: 1,
to: ['timeline:cpaentries']
});
ericFeed.addActivity({
actor: 'eric',
tweet: 'Hello world, Product CafeNew',
verb: 'tweet',
object: 1,
to: ['timeline:productcafe']
});
Now I am trying to ONLY retrieve the timeline containing cpaentries activities. Think of this as the main feed every user should see when they open the app. I'm just generally confused about client.feed, the to field and following as well I suppose.
const cpaToken = client.feed('timeline', 'cpaentries').token
var cpaFeed = client.feed('timeline', 'cpaentries', cpaToken);
cpaFeed.get({limit:5}).then(function(body) {
console.log(body);
/* on success */
}).catch(function(reason) {
console.log(reason);
/* on failure, reason.error contains an explanation */
});
This snippet basically just shows all posts, not only the cpaentries posts as I was hoping it would do.
Here's the body of my result:
{ results:
[ { actor: 'eric',
foreign_id: '',
id: 'd2435d01-21bb-11e8-81f8-128899f22c76',
object: '1',
origin: null,
target: '',
time: '2018-03-07T03:58:40.503118',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet' },
{ actor: 'eric',
foreign_id: '',
id: '83eb9b0e-21bb-11e8-a2ca-0a51ae8e7f7a',
object: '1',
origin: null,
target: '',
time: '2018-03-07T03:56:29.065704',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet' },
{ actor: 'eric',
foreign_id: '',
id: 'fc9b804e-2154-11e8-b02a-128899f22c76',
object: '1',
origin: null,
target: '',
time: '2018-03-06T15:42:33.381897',
tweet: 'Hello halli hallo world, CPA Entries',
verb: 'tweet' },
{ actor: 'eric',
foreign_id: '',
id: '3602f521-2152-11e8-853b-0a51ae8e7f7a',
object: '1',
origin: null,
target: '',
time: '2018-03-06T15:22:41.199850',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet' },
{ actor: 'eric',
foreign_id: '',
id: '281b133f-2152-11e8-8533-0a51ae8e7f7a',
object: '1',
origin: null,
target: '',
time: '2018-03-06T15:22:17.869808',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet' } ],
}

With the example below I thought that I'm first adding activities as Eric, I have one activity that goes just to Eric's feed, one that goes to the cpaentries feed and one that goes to the productcafe feed.
That's almost correct. In your example, all activities will go into Eric's feed. The second activity will go into Eric's feed, and be copied to the cpaentries feed. The third activity will go into Eric's feed, and be copied to the productcafe feed.
You can think of the to param as a collection of feeds to which the activity will be copied.
To get the behavior you thought would happen, the second and third activities would be added directly to the cpaentries and productcafe feeds respectively, with no to param. E.g.:
const cpaentriesFeed = client.feed('timeline', 'cpaentries', cpaentriesToken);
cpaentriesFeed.addActivity({
actor: 'eric',
tweet: 'Hello world, CPA EntriesNew',
verb: 'tweet',
object: 1
});
const productcafeFeed = client.feed('timeline', 'productcafe', productcafeToken);
productcafeFeed.addActivity({
actor: 'eric',
tweet: 'Hello world, Product CafeNew',
verb: 'tweet',
object: 1
});

Related

I am not able to pass my nested object from app.js to EJS file

I am finding for a particular ID in Workspace collection
Workspace.find({_id: requestedWorkspaceID} ,function(err, foundList) {
if(!err) {
if(foundList) {
console.log(foundList);
console.log(foundList.files);
// res.render("workspace.ejs", {files: obj.files});
}
}
})
Here is the picture of the output
console.log(foundList);
Its output is
[{
_id: new ObjectId("628e3a08f95d0929fab8ad25"),
name: 'Workspace 1',
files: [
{
filename: 'Default File 1',
filecontent: 'This is an example',
_id: new ObjectId("628e3a08f95d0929fab8ad22")
},
{
filename: 'Default File 2',
filecontent: 'This is an example',
_id: new ObjectId("628e3a08f95d0929fab8ad23")
},
{
filename: 'Default File 3',
filecontent: 'This is an example',
_id: new ObjectId("628e3a08f95d0929fab8ad24")
}
],
__v: 0 }]
I have used
require('util').inspect.defaultOptions.depth = null
that is why I am getting full visible object in my output. Before using require('util')..
my output was like this..
[{
_id: new ObjectId("628e3a08f95d0929fab8ad25"),
name: 'Workspace 1',
files: [ [Object], [Object], [Object] ],
__v: 0
}]
console.log(foundList.files);
Its output is undefined
I am not able to view my files (array of objects). I need to render the data present in files array of objects through EJS file. That is why I need to pass this whole foundList to workspace.ejs.
When I am passing it, i am getting an error in workspace.ejs that files is not defined.
Your array has one object inside. You should choose this object first and then get its files property:
console.log(foundList[0].files)
Result:
[
{
filename: 'Default File 1',
filecontent: 'This is an example',
_id: '628e3a08f95d0929fab8ad22'
},
{
filename: 'Default File 2',
filecontent: 'This is an example',
_id: '628e3a08f95d0929fab8ad23'
},
{
filename: 'Default File 3',
filecontent: 'This is an example',
_id: '628e3a08f95d0929fab8ad24'
}
]

Returning wrong intent should be buy_food not hello

I'm new using node-nlp but according to the examples I saw and the data I provided I should get a buy_food intent. But I'm not, it's returning hello intent. Any suggestions? If I remove the
manager.addDocument('en', 'hi', 'hello') line, it returns the right intent.
Any suggestions?
const { NlpManager } = require('node-nlp');
const manager = new NlpManager({ languages: 'en', ner: { threshold: 0.8 } });
manager.addNamedEntityText('drink', 'sprite', ['en'], ['sprite']);
manager.addNamedEntityText('size', 'large', ['en'], ['large', 'big']);
manager.addDocument('en', 'hello', 'hello');
manager.addDocument('en', 'hi', 'hello');
manager.addDocument('en', '%size% %drink%', 'buy_food');
manager.addDocument('en', 'i want %drink% please', 'buy_food');
manager.addDocument('en', 'i want %size% %drink% please', 'buy_food');
manager.addDocument('en', 'i want a %drink% please', 'buy_food');
manager.addDocument('en', 'i want a %size% %drink% please', 'buy_food');
manager.addDocument('en', 'i want to order a %size% %drink%', 'buy_food');
manager.addDocument('en', 'i want to order a %drink%', 'buy_food');
manager.addDocument('en', 'bye', 'bye');
manager.addDocument('en', 'bye bye', 'bye');
manager.addAnswer('en', 'hello', 'Welcome! How may I help you?');
manager.addAnswer('en', 'bye', 'Till next time');
manager.addAnswer('en', 'bye', 'see you soon!');
manager.addAnswer('en', 'buy_food', 'Got it, what else?');
manager.addAnswer('en', 'buy_food', 'Ok. Next item.');
var text = 'i want a large sprite';
(async () => {
await manager.train();
var result= await manager.process('en', text);
console.log(result);
})();
The result is
{ utterance: 'i want a large sprite',
locale: 'en',
languageGuessed: false,
localeIso2: 'en',
language: 'English',
domain: 'default',
classifications:
[ { label: 'hello', value: 0.5484776863751949 },
{ label: 'buy_food', value: 0.36024868417489125 },
{ label: 'bye', value: 0.09127362944991388 } ],
intent: 'hello',
score: 0.5484776863751949,
entities:
[ { start: 9,
end: 13,
len: 5,
levenshtein: 0,
accuracy: 1,
option: 'large',
sourceText: 'large',
entity: 'size',
utteranceText: 'large' },
{ start: 15,
end: 20,
len: 6,
levenshtein: 0,
accuracy: 1,
option: 'sprite',
sourceText: 'sprite',
entity: 'drink',
utteranceText: 'sprite' } ],
sentiment:
{ score: 0.29699999999999993,
comparative: 0.05939999999999999,
vote: 'positive',
numWords: 5,
numHits: 6,
type: 'senticon',
language: 'en' },
actions: [],
srcAnswer: 'Welcome! How may I help you?',
answer: 'Welcome! How may I help you?' }

node-nlp how to extract email, phone, url?

I'm using node nlp to extract the phone, url ,email etc. The sample code given was just an object in the help page. I don't know how to initialize the extract code. The read me for extraction url is https://github.com/axa-group/nlp.js/blob/master/docs/builtin-entity-extraction.md#ip-extraction
One of the sample in that page is given below.
Email extraction
It can identify and extract valid emails accounts, this works for any language.
"utterance": "My email is something#somehost.com please write me",
"entities": [
{
"start": 12,
"end": 33,
"len": 22,
"accuracy": 0.95,
"sourceText": "something#somehost.com",
"utteranceText": "something#somehost.com",
"entity": "email",
"resolution": {
"value": "something#somehost.com"
}
}
]
I have installed the npm and initialized like this
const { NlpManager } = require('node-nlp');
const manager = new NlpManager({ languages: ['en'] });
What must be the next steps(Need a sample code) to do the extractions?
The npm url is : https://www.npmjs.com/package/node-nlp
I will provide you an example code:
const { NlpManager } = require('node-nlp');
const manager = new NlpManager({ languages: ['en'] });
async function mainExtractEntities() {
const result = await manager.extractEntities('en', 'Are you able to identify that meh#meh.com is an email and moh#moh.com is another email so there are 2 emails?');
console.log(result);
}
async function mainFullExample() {
manager.addDocument('en', 'My mail is %email%', 'email');
manager.addDocument('en', 'My email is %email%', 'email');
manager.addDocument('en', 'Here you have my email: %email%', 'email');
manager.addDocument('en', 'Hello', 'greet');
manager.addDocument('en', 'Good morning', 'greet');
manager.addDocument('en', 'good afternoon', 'greet');
manager.addDocument('en', 'good evening', 'greet');
manager.addAnswer('en', 'email', 'Your email is {{email}}');
manager.addAnswer('en', 'greet', 'Hi!');
await manager.train();
let result = await manager.process('en', 'I think that my mail is meh#meh.com');
console.log(result);
result = await manager.process('en', 'Hello bot!');
console.log(result);
}
mainExtractEntities();
mainFullExample();
This will show in console:
[ { start: 30,
end: 40,
len: 11,
accuracy: 0.95,
sourceText: 'meh#meh.com',
utteranceText: 'meh#meh.com',
entity: 'email',
resolution: { value: 'meh#meh.com' } },
{ start: 58,
end: 68,
len: 11,
accuracy: 0.95,
sourceText: 'moh#moh.com',
utteranceText: 'moh#moh.com',
entity: 'email',
resolution: { value: 'moh#moh.com' } },
{ start: 100,
end: 100,
len: 1,
accuracy: 0.95,
sourceText: '2',
utteranceText: '2',
entity: 'number',
resolution: { strValue: '2', value: 2, subtype: 'integer' } } ]
{ locale: 'en',
localeIso2: 'en',
language: 'English',
utterance: 'I think that my mail is meh#meh.com',
classification:
[ { label: 'email', value: 0.9994852170204532 },
{ label: 'greet', value: 0.0005147829795467752 } ],
intent: 'email',
domain: 'default',
score: 0.9994852170204532,
entities:
[ { start: 24,
end: 34,
len: 11,
accuracy: 0.95,
sourceText: 'meh#meh.com',
utteranceText: 'meh#meh.com',
entity: 'email',
resolution: [Object] } ],
sentiment:
{ score: 0.25,
comparative: 0.027777777777777776,
vote: 'positive',
numWords: 9,
numHits: 1,
type: 'senticon',
language: 'en' },
srcAnswer: 'Your email is {{email}}',
answer: 'Your email is meh#meh.com' }
{ locale: 'en',
localeIso2: 'en',
language: 'English',
utterance: 'Hello bot!',
classification:
[ { label: 'greet', value: 0.8826839762075465 },
{ label: 'email', value: 0.1173160237924536 } ],
intent: 'greet',
domain: 'default',
score: 0.8826839762075465,
entities: [],
sentiment:
{ score: 0,
comparative: 0,
vote: 'neutral',
numWords: 2,
numHits: 0,
type: 'senticon',
language: 'en' },
srcAnswer: 'Hi!',
answer: 'Hi!' }
Important things to know:
You can omit the language in the extractEntities and process and pass undefined instead, that way the language will be guessed from your sentence to fit the best language of your NlpManger.
The email extraction works for any language. You have other entities more complex, like text numbers, that will be extracted only for some languages
The entity extraction is only one part, other interesting partes are the NLU classifier and the Natural Language Generation, you will see that the answer "Your email is {{email}}" is a template and the email is replaced with the extracted one from the conversation.

Load Email messages attached to transaction Suitescript 2.0

I'm trying to load up all of the emails that have been sent from a transaction via SuiteScript 2.0.
When I run
record.getSublists()
it returns the following:
["item","activeworkflows","workflowhistory","custom8","messages","contacts","activities","usernotes","systemnotes","mediaitem","links","cases","partners","events","calls","tasks"]
However, when I then try to run the following:
record.getSublist('messages');
I receive an error.
I need to be able to check the date of the last email sent so I can determine whether or not to send a follow-up email.
The approach I typically take is to use the Search API to get this type of information:
require(['N/search'], function(search) {
var result = search.create({
type: 'transaction',
filters: [
['internalid', search.Operator.ANYOF, id], 'AND',
['mainline', search.Operator.IS, 'T'], 'AND',
['messages.messagetype', search.Operator.ANYOF, 'EMAIL'], 'AND',
['messages.isincoming', search.Operator.IS, 'F']
],
columns: [
search.createColumn({name: 'internalid', summary: search.Summary.GROUP}),
search.createColumn({name: 'messagedate', join: 'messages', summary: search.Summary.MAX}),
],
}).run().getRange({ start: 0, end: 1 });
var dateOfLastEmail = result[0].getValue({ name: 'messagedate', join: 'messages', summary: search.Summary.MAX });
});

Querying a result returned by mongoose in nodejs

I am relatively new to Node.js, Mongoose and MongoDB.
I want to perform filter functionality and want to filter products by criteria selected by the user.
Is it possible in Node.js to query a response returned by Mongoose?
Sample response from Mongoose as below:
[ { _id: 589860c21f9997fce3502f10,
title: 'Watch',
brand: 'PUMA2',
store: 'ZARA',
for: 'MALE',
size: '32',
colour: 'RED',
userId: '58a420cd7c77aca4b3ce34cd' },
{ _id: 5899bd33c28dbdf2b938f698,
title: 'Watch 2',
brand: 'PUMA',
store: 'ZARA',
for: 'MALE',
size: '32',
colour: 'RED',
userId: '58a420cd7c77aca4b3ce34cd' },
{ _id: 5899bd59c28dbdf2b938f69a,
title: 'Watch 4',
brand: 'PUMA',
store: 'ZARA',
for: 'MALE',
size: '32',
colour: 'RED',
userId: '5899bde3c28dbdf2b938f69e' }]
Now how can I query this response to select data based on brand.
For finding PUMA brand, then query will be
db.collection.find({'brand': 'PUMA'})
Thanks for help everyone, finally got nice plugin called array-query which helped me to achieve what I want.
https://www.npmjs.com/package/array-query

Resources