Custom content type Version 11.8.4

#1

I have flowed the tutorial of internationalization to create custom content type.


I added new file “translated_text.js” under “data/global/content-types/extensions” folder

"use strict";

function renderElement(data, channel) {
  const language = data.state.language || 'En'
  return [
    {
      type: 'text',
      typing: true,
      markdown: true,
      text: data[`text${language}`],
      'web-style': { direction: language === 'Ar' ? 'rtl' : 'ltr' }
    }
  ]
}

module.exports = {
  id: 'translated-text',
  group: 'Extensions',
  title: 'Translated Text',
  jsonSchema: {
    description: 'A normal text message with translations',
    type: 'object',
    required: ['textEn', 'textAr'],
    properties: {
      textEn: { type: 'string', title: 'Text (English)' },
      textAr: { type: 'string', title: 'Text (Arabic)' }
    }
  },
  uiSchema: {},
  computePreviewText: formData => formData.textEn + ' / ' + formData.textAr,
  renderElemnet: renderElement
};

Then i restarted the bot and in the log i found that CMS loaded the new content, but when i open the studio i did not find the new content added.

10:15:37.656 Launcher ========================================
                                  Botpress Server            
                                   Version 11.8.4             
                                  OS linux ubuntu            
                      ========================================
10:15:38.705 Launcher Using 8 modules
                      ⦿ MODULES_ROOT/analytics
                      ⦿ MODULES_ROOT/basic-skills
                      ⦿ MODULES_ROOT/builtin
                      ⊝ MODULES_ROOT/channel-messenger (disabled)
                      ⊝ MODULES_ROOT/channel-telegram (disabled)
                      ⦿ MODULES_ROOT/channel-web
                      ⦿ MODULES_ROOT/extensions
                      ⦿ MODULES_ROOT/hitl
                      ⦿ MODULES_ROOT/nlu
                      ⦿ MODULES_ROOT/qna
10:15:40.496 Server Loaded 8 modules
10:15:40.523 CMS Loaded 8 content types
10:15:40.733 Server Started in 2027ms
10:15:40.734 Launcher Botpress is ready at http://localhost:3000/

image

Please advise.

#2

My issue resolved after i added the new content type to my bot config under contentTypes section

#3

When i add new content type element to my flow and run the bot, i get below exception.

2019-05-13T10:56:22.382Z bp:dialog (tasheel-platinum-bot-en) [mesz55y2x8798cb73lpy10zmhhfgb] render element "#!translated-text-niGjo2"
10:56:22.384 DialogEngine Error processing "say #!translated-text-niGjo2"
                          Err: undefined is not a function
                          Flow: main.flow.json
                          Node: entry [Error, undefined is not a function]
STACK TRACE
Error: undefined is not a function
    at DialogEngine._reportProcessingError (/snapshot/build-linux/out/bp/core/services/dialog/dialog-engine.js:0:0)
    at DialogEngine.<anonymous> (/snapshot/build-linux/out/bp/core/services/dialog/dialog-engine.js:0:0)
    at Generator.throw (<anonymous>)
    at rejected (/snapshot/build-linux/out/bp/core/services/dialog/dialog-engine.js:0:0)
    at tryCatcher (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/promise.js:690:18)
    at _drainQueueStep (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/administrator/botpress/modules/.cache/module__885e39cf78c7dd48c8d981658971d8ce6f037ad3e4c2b981eee9ddf377f69bf3/node_production_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:696:18)
    at tryOnImmediate (timers.js:667:5)
    at processImmediate (timers.js:649:5)
    at process.topLevelDomainCallback (domain.js:121:23)

Please advise.
Thanks

#4

Hi @abdelazizelesh,

Unfortunately this doc is outdated and i18n has changed quite a bit. i18n is now built in the UI and you shouldn’t have to add anything to the code. When you start Botpress, it will ask you for your default language and you’ll have an option in the CMS to set content for each language. Documentation will be updated, but meanwhile I will take it down.

Also it should be noted that i18n is a Pro feature. The other option would be to create a second bot in another language if you’re using the community edition.