Develop with Content Agent
How to use Content Agent functionality in your plugin
Getting started
Content Agent gives you methods to use in your plugin such as opencontent to be able to do search/suggest requests from OpenContent by passing your search query for example!
Content Agent register it's own methods with Dashboard Actions
You can use any of these actions in your plugin.
Available actions
ID
Descriptions
com.naviga.content-agent:getProviders
An action to return all available provider names (from config)
com.naviga.content-agent:getInstance
An action returns the instance of Content Agent with Opencontent, Querystreamer and Infocaster methods
With getInstance action you will get a fully powerful class that has three main instances:
opencontent:
search - promise request.
request - promise request
suggest - promise request
querystreamer
activeStreams
createStream
deleteStream
infocaster
activeSubscriptions
broadcast
subscribe
unsubscribe
An example to how to get Content Agent instance
In your plugin you can import useAction from Dashboard, so you can "import" Content Agent actions to your plugin.
Here we used com.naviga.content-agent:getInstance action to get and initiate our CA instance, and listening on CA status changes with onStatusChange
Open Content
To access Open Content you call CA.opencontent() with the name of content provider you want to use (from config).
Access to search and suggest is simplified by two helper functions, but any OC REST API endpoint can be reached using the request function. The functions returns promises.
Open Content API Documentation
Search
Suggest
Generic OC API request
QueryStreamer
To handle streams in QueryStreamer you call CA.querystreamer() with the name of content provider you want to use (from config).
createStream and deleteStream is enabled on this instance.
QueryStreamer API Documentation
ElasticSearch Query Format Documentation
Create stream
When calling create stream, pass a request object and a callback function as parameters. This will return a promise that resolves with a stream ID. New events will land in the callback function you provided.
Delete stream
Cleanup
When a stream is no longer needed, delete it.
Please don't forget call deleteStream(streamId)
If you are creating a stream in a class component you can delete the stream when your component unmounted with
componentWillUnmount.If you are creating a stream in a hook component you can delete the stream when your component unmounted with returning a function with
useEffectIf you are creating a stream in the Agent you can delete the stream when your Agent close with
close
Last updated
Was this helpful?