Add contents

Using our SDK you can easily add contents as well. This gives you the benefit of creating new content directly from your app.

In order for contents to be pushed to the CMS, please make sure the Allow to push data to Dialoguewise setting is enabled in your API key settings.

First you need to prepare the AddContentsRequest request payload and for that you will need to import the corresponding request object.

import 'package:dialogue_wise/DTOs/add_contents_request.dart';

Next, you need to prepare the payload by setting the slug, accessToken and source. source can be any text and allows you to identify the source of the content being added.

var request = new AddContentsRequest();
request.slug = '<Provide Slug>';
request.accessToken = '<Provide access token>';
request.source = '<Provide a source name>';

Now, we add the fields and its corresponding content

List<Field> fieldList = [];
var field = new Field();
field.name = '<Provide field name>';
field.value = '<Provide the content>';
fieldList.add(field);
.
.
.
field = new Field();
field.name='[Name of field]';
field.value='[Content for field]';
fieldList.add(field);

Once you have added all the fields and its corresponding content you then set it to the content property. You can also set any metadata if you need to, this is completly optional.

List<Content> contentList = [];
var content = new Content();
content.fields = fieldList;
content.metadata = new ContentMetadata();
content.metadata!.deviceType = Device.SmartWatch;
contentList.add(content);
request.contents = contentList;

Now, the payload is ready and you just need to call the addContents service.

var dialogueWiseService = new DialoguewiseService();
var response = await dialogueWiseService.addContents(request);

That’s it! You will now get a response which will indicate if your content was added successfully.

For mode details on the implementation, please have a look at the examples available on Github.

Please note, all the contents that are added will be added as a draft version. You will need to deploy your Dialogue for it to be available. To understand further, please have a look at Deploying your Dialogue.