Get activity body from activity ID - getstream-io

How can I use the PHP getstream API to retrieve all the information about an activity from the activity id?
When we add activities we locally store the ID's for them, how could we get the activity body given that activity id 5c23d1be-0dc5-12e6-2080-1000759b484d using the php API?

One way to retrieve this single activity using the Stream PHP client would be:
$options = array("id_lte" => $uuid);
$results = $user_feed_1->getActivities(0, 1, $options);
Also, one thing you can do is to set foreign_id which can be used as a unique id to retrieve/delete/update an activity:
// Remove an activity by its id
$user_feed_1->removeActivity("e561de8f-00f1-11e4-b400-0cc47a024be0");
// Remove activities with foreign_id 'run:1'
$user_feed_1->removeActivity('run:1', true);

Related

Issue in reading paginated API data using ADF

I am trying to read the data from a paginated API using ADF copy activity. While accessing the API at first time, only the base URL is used(without any query params). When API returns the data, it will have a key called cursor with some token. This has to be passed as query string to get the next page. How to implement this using ADF?. How to append "?cursor=" in the base URL and then add cursor value from API response
First Page : {{Base URL}} #returns a JSON with a key called cursor
From Second Page : {{Base URL}}?cursor = {{value of cursor key in JSON Response}}
I have tried using Query Parameters inside the Copy Activity of pagination. But it is not working
You can use web activity to the cursor value and pass it to the relative URL in copy activity.
You can first make a call with the base URL using web activity.
Parameterize the relative URL in the dataset.
Connect web activity to copy data activity and pass the web activity output required value to the copy activity dataset parameters to run the URL with cursor value.
Ex: #concat('?cursor=',activity('Web1').output.cursor)

Pushing visitor data from DialogFlow to ZohoCRM

So I have connected DialogFlow to Zobot (Zoho Chatbot) and want to push information from DF to ZohoCRM.
My chatbot could sign someone up to a newsletter and once the person gives me their email I want to save that email and name in the ZohoCRM.
From what I can gather I have to use the DF webhooks to send information anywhere, I have found a sample code that can push data to the ZohoCRM but I want to customise it.
My main questions:
If I have a user email that is stored in DF as #sys.email how do I refer to this value in my web-hook code?
How do I specify what table and column the information must be stored in?
Where do I set my Zoho CRM ZSC Key?
This is code taken from the Zobot integration documentation page (https://help.zoho.com/portal/community/topic/schedule-a-call-and-push-visitor-data-to-zoho-crm-with-zobot-26-11-2018):
info crmdata;
if(!crmdata.isEmpty())
{ // update existing
_crmdata = crmdata.get(0);
info _crmdata;
leadid = _crmdata.get("id");
crmdata = zoho.crm.update("Leads",leadid,{"Full_Name":name},Map(),"your CRM connection name");
}
else
{
// create new lead
crmdata = zoho.crm.create("Leads",{"Email":email,"Full_Name":name},Map(),"your CRM connection name");
}
leadid = crmdata.get("id");
info leadid;
1.If I have a user email that is stored in DF as #sys.email how do I refer to this value in my web-hook code?
When user will be added to zoho crm you can start with workflow rule function which will be adding the variable you want to.
How do I specify what table and column the information must be stored in?
You can not specify table or column where the information must be stored in. You can only add new one user. I've tried it many times, sorry ;/

getstream-io: Using getActivities with an aggregated feed id

I have an aggregated feed ID in the format 46702136-5b7a-11e9-8080-80007f00215c.verb:id_2019-04-10.
When I call client.getActivities with this ID, I get an error "Invalid activity ID". I've tried just using the first part of the ID but this fails to return anything.
Is there a reason this doesn't work, or an alternative?
The get activities endpoint allows you to retrieve individual activities, not aggregated activities.
This is because aggregated activities are specific to individual feeds and their feed group.
If you want to fetch an activity inside a group, you can still use client.getActivities eg.
client.getActivities(group.activities[0].id)
Otherwise if you want to fetch a single aggregated activity from a specific feed; you can do something like this:
feed.get(
id_lte=group.id,
id_gte=group.id,
limit=1
)

A way to mark notification as seen without reading the notification feed?

My situation is the following:
I'm using the stream-js library. I add entries to the notification feeds of users for certain events - comments, follows, etc. After I write to their feed I also send a push notification to that user's device.
If a user clicks on a push notification I want to be able to mark the corresponding activity as seen. There's currently no way to do that since the add or addToMany calls do not return the ids of the added activities for me to send in the notification payload.
Ideally I'd want a way to mark a notification feed item as seen either by an activity group id or by some other unique id (or the foreignId). Is there a way to do that? If not, what is the alternative?
Two parts to this answer:
Getting the ID of an activity that you just added
The addActivity call in the various Stream client libraries (I'm using stream-js in this case) will return back the created activity, which should include the activity ID. Response looks something like this:
{
actor: 'ken',
duration: '9.65ms',
foreign_id: '',
id: '8b5d69a9-8b73-11e8-98ab-12cb9e7b86a4',
object: 'some-object',
origin: null,
target: '',
time: '2018-07-19T16:48:21.045496',
verb: 'add-activity'
}
Marking notification feed items as seen or read
The way to mark a notification feed item as seen or read is a little funky - first, you get the feed, like you would normally do, but you'll also pass in the mark_seen or mark_read options. (true will mark all items as seen or read, and an array of activity group IDs will mark only those items.)
From that call, the notification feed will be returned without the items marked as seen or read - but the next call to retrieve the notification feed will have the items marked accordingly.
More docs on that here: https://getstream.io/docs/flat_feeds/#notification_feeds
activity ID --> activity group ID
You might have noticed that you get the activity ID when adding the activity, but you need to pass in the activity group ID when marking items seen or read.
All notification feeds are actually aggregated feeds as well - by default, the aggregation format that they use is just the activity ID, which means that there will be only one activity per activity group, and the activity group ID will be the same as the activity ID. So, you can just use the activity ID returned by the addActivity call to get the notification feed and mark that activity group as seen or read.
If you're not using the default aggregation format (e.g., the activity group ID is not the same as the activity ID), then you'll likely have to retrieve the notification feed and grab the necessary activity group ID from there.

Related objects in activity feed

I'm building an activity feed application, where a user can like/comments on each activity feed. I went through GetStream.io documentation and looks like I'll have to send the activity with object ids.
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
object:"Comment:12",
started_at:"2014-11-11T15:06:16+01:00",
target:"Feed:100",
time:"2014-11-11T14:06:30.494",
verb:"add"
}
User:1 and Feed:12 are the objects in my application database? Does it mean that, while retrieving activities, I'll have to hit my database to retrieve the complete feeds?
Say the Feed:12 had few likes and comments earlier from other users. How do I get the complete set of likes/comments on user timeline feed?
What if I want to customize the view, say I want to show all users (image, name, the profile like etc) along with comment with timestamp similar to FB? Do I need to send these attributes as additional parameters for each feed?
Thanks,
Yes, when you fetch a feed from Stream and we give you back these references like user:1 or comment:12, we expect that you'd "enrich" those details from your database.
Typically what our users do is track the name of the model (eg, user) and the user_id (eg, 1). When you get the feed and put it into a hash map, you'll iterate over the activities, pull out all of the actor attributes, and do a single lookup like select * from user where id in (1,3,5,6,9,12) so that you're only hitting your database one time for all user objects or all comment objects or whatever. Then, replace those activities in your hash map so now you'd have actor: <object for User 9> and any other attributes you'd need for your UI presentment.
Then do the same for other references you pass in the activity, and so on.
Things we DON'T recommend are putting in string references for things that could change on your side. For example, if you had actor: "user:ian" instead of my user_id, if I ever change my username later then things probably wouldn't work properly on your side.

Resources