Closed taraa62 closed 5 years ago
I figured out a bit with the engine and realized that transferring the image in bytes would be problematic and found a way out for myself how to send the desired image to the chat from another service.
The problem is how to transfer url to core. I did a little bang and put a crutch in the file "cms.ts /" function "renderElement" If we make a request for another service, and there we take the url dynamically to the picture, then we will not be able to send it to the user in any way if it does not lie on the server and we do not do it through the necessary node. Therefore, this function needs to be expanded to: ` if (contentId.startsWith('!')) {} else { contentTypeRenderer = await this.getContentType(contentId) if (args.text) { args = { ...args, text: renderTemplate(args.text, args) } } try { let content: any = { botId: botId, contentType: contentId, formData: { image$en: args.image, title$en: 'title', subtitle$en: 'subtitle', typing: args.typing } } contentTypeRenderer = this.getContentType(contentId)
const defaultLang = (await this.configProvider.getBotConfig(eventDestination.botId)).defaultLanguage
const lang = _.get(args, 'event.state.user.language')
const translated = await this.getOriginalProps(content.formData, contentTypeRenderer, lang, defaultLang)
content.formData = translated
_.set(content, 'formData', renderRecursive(content.formData, args))
args = {
...args,
...content.formData
}
console.table(11)
} catch (e) {
console.error(e)
}
}
This is not perfect and I just wanted to start and check if it will work at all. Now how to use it. Create a new "action" and something like this:
const element = {
image: "https://i.ytimg.com/vi/ElRfLW-NSjE/maxresdefault.jpg",
typing: true //?
};
const payloads = await bp.cms.renderElement("builtin_image", element, event);
bp.events.replyToEvent(event, payloads);
`
If there is a ready-made implementation, you can suggest how to do it differently and if not, you can add something like that, you really need this functionality.
this is great, it works for me
but is there any solution to tell messenger to show the image with it's real size and not strecth it to fit the screen size ??
best
I want to get a picture from another service and send it to the user in a telegram, but I can not figure out how to do it
const { data } = await axios.get('https://png.pngtree.com/element_origin_min_pic/17/08/13/6ccb6a40010c1ac018e8480679313a29.jpg')
I use it:const payload = await bp.cms.renderElement('builtin_image', { image: data }, event) await bp.events.replyToEvent(event, payload)
but, it's not work.