RocketChat PostMessage using attachments fields - rocket.chat

i'm trying to send a custom message using attachments fields
{
title: 'Markdown Test',
value: '`hi`',
short: false
},
{
title: 'Markdown Test',
value: '```hi```',
short: false
}
But when I recieve this message at the brower the markdown is not rendered.
I noticed the inline_code and the multi line code markdown is not been rendered.
What i'm doing wrong?
Best regards, Amandio Magalhaes

Related

how to send formatted messages to rocketchat from hubot?

I would like to prepare formatted messages to rocketchat from hubot but I can't find any reference for that.
That's my main reference:
http://theprogrammingbutler.com/blog/archives/2011/10/28/hubot-scripts-explained/
I have tried this:
msg.http(url)
.headers("PRIVATE-TOKEN": api_key, Accept: 'application/json')
.get() (err, response, body) ->
try
json = JSON.parse(body)
for issue in json
msg.send "#{issue.title}"
catch error
msg.send "Sistema not found."
console.log(error)
But I would like some more rich and elaborated.
Any sugestion ??
Thanks.
The hubot adapter for Rocket.Chat has a method called customMessage. You can include attachments like you would with slack to achieve rich messages.
To use customMessage use something like this:
robot.adapter.customMessage({
channel: room,
attachments: [
{
title: "New Event",
title_link: "http://example.com/event",
text: "<img src=\"http://example.com/picture\" width=\"20\" /> Event 1234: <br /> urgent event"
}
]
});
I had a similar need. What worked for me was using the image_url field, documented in the realtime API documentation:
module.exports = function(robot) {
robot.respond(/image/i, function(res) {
resposta = robot.adapter.customMessage({
channel: room,
attachments: [
{
title: "Image",
title_link: "http://www.example.com",
image_url: "http://www.example.com/image.png",
text: "This image"
}
]
});
});
};

How can I read a local file in Cloud Code as a string?

I'm using Parse Cloud Code.
My system has a welcome message. I use MailGun to send it.
The problem I have is that the message now is an HTML file, so I would like to let the HTML file in my server, read it using Cloud Code and pass that info to MailGun.
Can I read a local text file using Cloud Code and have it in my program as a string?
Should I save that file in my public folder or in the same folder than my cloudcode program?
I'm not confident with MailGun, but I believe it should work like MailChimp or Mandrill. If so, you should be able to store on MailGun your whole HTML template and just have some template_vars to complete.
This is a sample code of our own way to send mail with HTML thanks to the Mandrill system
Parse.Cloud.define("sendMailTemplate", function(request, response) {
var emails = request.params.emails;
var template_name = request.params.template_name;
var template_merge_content = request.params.template_merge_content;
var subject = request.params.subject;
var Mandrill = require('cloud/mandrillTemplateSend.js');
if (subject === undefined) {
subject = 'Mail sent by Mandrill';
body = subject;
}
Parse.Config.get().then(function(config) {
Mandrill.initialize(config.get('Mandrill_key'));
}).then(function() {
_.each(emails, function(email) {
Mandrill.sendTemplate({
template_name: template_name,
template_content: [{
name: template_merge_content.username,
content: ''
}],
message: {
text: '',
subject: subject,
from_email: 'contact#yourdomain.com',
to: [{
email: email,
name: template_merge_content.username
}],
merge_vars: [{
rcpt: email,
vars: template_merge_content
}],
},
async: false
});
});
}).then(function() {
response.success('Success');
}, function(error) {
response.error(error);
});
});
This object template_merge_content is quiet important. It's an object where is saved all the dynamic vars which are send to complete your HTML mail.
According to http://blog.mailgun.com/transactional-html-email-templates/ it seems you have same kind of method to send your mail.
So final advice would be to NOT store your HTML template within any Parse's class, or to save it within https://parse.com/docs/js/api/symbols/Parse.Config.html

kendo window in iframe mode : the URL is not being requested from the server

I think the following is a valid configuration:
var wdiv = $("#messagewindow");
if (!wdiv.data("kendoWindow")) {
wdiv.kendoWindow({
iframe: true,
width: "777px",
height: "666px",
title: "foo title",
data: { startdate: urldate, eeid: eeid, deptid: deptid },
url: "foo.htm",
type: "GET"
});
}
wdiv.data("kendoWindow").open();
The window opens, but there's no network activity. Foo.htm is not being requested from the server according to Fiddler.
Am I neglecting something in the configuration?
There is not such things as url when creating.
http://jsbin.com/umuzil/1/edit
What you look for is called content. Url is used when refresh-ing the window.
The option for specifying the url is content. Documentation in here.

Extjs 4 (with a code for 3.4 below) downloading a file returned from a post request

I have seen questions slightly related to this, but none that answer my problem. I have set up an Ext.Ajax.request as follows:
var paramsStringVar = 'param1=1&param2=two&param3=something&param4=etc';
Ext.Ajax.request({
url: '/cgi-bin/url.pl',
method:'POST',
params:paramsStringVar,
timeout:120000,
success: function(response, opts){
var objhtml = response.responseText; //content returned from server side
console.log(objhtml);
}
});
This request retrieves the appropriate content from the backend. One parameter is outputType, which can take values {html, excel, csv}. When returning html to display I am able to handle and display it correctly. Now on to the problem...
When I set the outputType parameter to csv or excel, I get back the appropriate content as csv or tsv(excel) as requested. BUT, I don't want the content, I want a prompt to download the file(csv or excel). How can I have the browser auto prompt the user to download the file instead of just retrieving the text content within extjs?
Version 4.07 so I can't use any 4.1 only features
There seems to be no bulletproof solution but there are several approaches I would try:
1) Use an iframe instead of real XHR to POST data to the server, e.g. <form action="/something" target="myiframe"> where myiframe is the name of your hidden iframe. That way your form would use the iframe (not your main window) to submit data to the configured URL. Your server should set response header as application/octet-stream (or some ither MIME type for binary data) so the browser triggers download. Otherwise (if html returned in your case) you can just retrieve iframe's body innerHTML and display it to the user in UI. While using an iframe (or a new window) instead of XHR doesn't sound like the best idea, this solution seems to be the most reliable so far (and with best browser support).
Here is a slightly modified example from Ext.form.Basic docs page:
Ext.create('Ext.form.Panel', {
title: 'Basic Form',
renderTo: Ext.getBody(),
width: 350,
// Any configuration items here will be automatically passed along to
// the Ext.form.Basic instance when it gets created.
// *THIS* makes the form use a standard submit mechanism, not XHR
/**/standardSubmit: true,
// URL to submit to
url: 'save-form.php',
items: [{
fieldLabel: 'Field',
xtype: 'textfield',
name: 'theField'
}],
buttons: [{
text: 'Submit',
handler: function() {
// The getForm() method returns the Ext.form.Basic instance:
var form = this.up('form').getForm();
if (form.isValid()) {
// Submit the Ajax request and handle the response
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
},
// You can put the name of your iframe here instead of _blank
// this parameter makes its way to Ext.form.Basic.doAction()
// and further leads to creation of StandardSubmit action instance
/**/ target: '_blank'
});
}
}
}]
});
There are two key parameters here (lines marked with /**/):
standardSubmit: true config that you pass to your form will make it do a standard submit instead of XHR.
Passing a target parameter to the form's submit action. This feature is not documented but you can see it being used in Ext.form.action.Submit source code (all options that you pass to Ext.form.Basic.submit() method end up as parameters of Ext.form.action.* instance.
In the example code I put target: '_blank' to demonstrate that it works right away (will create a new browser window). You can replace it with the name of your iframe later but I suggest that you first test how your form submits data to a regular new window and then develop logic that creates and processes an iframe. You will have to process the result inside iframe yourself, thought. It's not that difficult, see Ext.data.Connection.upload() implementation as an example of iframe processing.
ExtJS actually already uses the iframe technique for file uploads. See Ext.data.Connection and Ext.form.field.Field.isFileUpload() for an idea of how it can work.
2) Suggested here: Using HTML5/Javascript to generate and save a file.
If you don't want to go the iframe way, you can try generate data URI from response data and navigate to that URI triggering download:
content = "Hello world!";
uriContent = "data:application/octet-stream," + encodeURIComponent(content);
window.location.href = uriContent;
Again, mimetype is essential here. This worked for me, you should note, however, that browsers impose a size limit to data URIs (256Kb is a safe bet).
3) Another answer in the mentioned thread links to FileSaver.js library the implements the (abandoned?) w3 spec. Usage and demo here. It uses [BlobBuilder] to generate a blob of binary data that is further used to initialize downloads using one of several methods. While this solution seems to work, it uses deprecated APIs and may not be future-proof.
Below is my solution. This is how I have it currently working. The response generates a download/open prompt, based on a response type of text/csv. Note that no iFrame or reference to an iframe are needed. I spent a lot of time hung up on the need for an iFrame, which actually broke my solution. An iFrame is not needed to generate a download prompt. What is needed is a request(submittal) similar to this one, along with a backend generating the appropriate csv with text/csv response header.
var hiddenForm = Ext.create('Ext.form.Panel', {
title:'hiddenForm',
standardSubmit: true,
url: /cgi-bin/url.pl
timeout: 120000,
height:0,
width: 0,
hidden:true,
items:[
{xtype:'hiddenField', name:'field1', value:'field1Value'},
// additional fields
]
})
hiddenForm.getForm().submit()
The standardSubmit line is vital
You don't need to create a form panel and make it hidden in your extjs file. We can add a html form and on click of button in extjs file we can submit the form using the url. This will work both in IE as well as chrome browsers. Below is my code i tried and its working fine,
<form action="<%=fullURL%>/DownloadServlet.do" method="get" id="downloadForm" name="downloadForm" target="_self">
</form>
click:
{
fn: function()
{
document.getElementById('downloadForm').submit();
}
}
To get it working on ExtJS 3.4:
var hiddenForm = new Ext.FormPanel({
id:'hiddenForm',
region: 'south',
method: 'POST',
url: "/cgi/test.wsgi",
height: 0,
standardSubmit: true,
hidden:true,
items:[
{xtype:'hidden', name:'p', value:p},
{xtype:'hidden', name:'g', value:g},
// ...
],
});
linkThis = new Ext.Button({
text: 'Download this CSV',
handler: function() {
hiddenForm.getForm().submit();
},
maxHeight: 30,
});
Remember that in order to make it working, you should put the hiddenForm in any container (i.e. in the same Ext.Window of the button), for example:
risultatiWindow = new Ext.Window({
title: 'CSV Export',
height: 400,
width: 500,
....
items: [...., hiddenForm]
});

Retrieve multiple API's using ID

I have 2 APIs which I want to use simultaneously, API1 and API2.
API2 deliver news feeds to API1, while API1 handles all the content in a list form. This means that if any list in API1 is clicked on, it will it will retrieve the the news feeds from API2 using an ID that has been defined.
Who can help me out here? I am stuck. The screenshot of my code is here: http://i1159.photobucket.com/albums/p637/Apulo_Cosmas/2API.jpg
Thanks so much.
Per the Sencha documentation here (under Digging In): http://docs.sencha.com/touch/2-0/#!/guide/first_app
You need to add a listener and a detail panel to your configuration, using this code (reference to contentId is not needed, you just need to pull the description property -- which contains the content -- from the original feed):
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
itemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('description'));
}
}
It might be easier if you manually listen to your list (which is fetched from API 1) itemtap event.
In your controller, there's should be something like:
refs: {
bloglist: 'blog list'
},
control: {
bloglist: {
itemtap: 'fetchAPI2'
}
},
fetchAPI2: function (list,index,target,record){
id = record.get('contentId'); //this is your id for using API2.
Ext.data.JsonP.request({
scope: this,
url: API2_URL,
callbackKey: 'callback',
params: {your params for API2 here},
callback: function(success,result) {
// whatever you want to do here
}
});
}

Resources