Formatting posts with the Slack api - slack-api

I'm trying to create Posts with botkit using the Slack api, but I can't find any documentation on how to format a Post file in Slack.
bot.api.files.upload({
content: "# Heading",
filename: "test.md",
filetype: "post",
channels: "random"
});
Markdown formatting doesn't work for this, is there any syntax to formatting Slack Posts?
Trying with HTML the response from the created file is like this:
<document><p><document><h1>H1<\/h1><p><\/p><h2>H2<\/h2><p><\/p><h3>H3<\/h3><p><\/p><p>Text <i>italic<\/i> <b>bold<\/b> <a href="<a href=\"http:\/\/www.slack.com%22%3Elink%3C\/a%3E\">http:\/\/www.slack.com">link<\/a><\/a> <u>underline<\/u><\/p><p><\/p><p><strike>strikethrough<\/strike><\/p><p><\/p><p><code>Code Block;<\/code><\/p><\/document><\/p><\/document>
so it's escaping html tags.

Posts support markdown formatting.
E.g., try setting the following content:
# A Post Header
### Subheading
An image? ![Funny](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4jlx3aktZVFKAkaNB7fvy67BFQuaO3HedVQ6VIXeR5OLnfbOOEbrcp-G4)
[A link to google](https://www.google.com)
* A list item
* Another list item
`a code block`
You then post with filetype="post", and get the following:
I tested and slack appears to support most markdown features but not all. Make sure to test your formatting!

Related

How to set links dynamically in Sendgrid v3 using javascript (node.js)

I am trying to add a unique link to a sendgrid template, but so far I have had no luck. The button in the sendgrid is the following:
Accept
I have also tried:
Accept
My javascript function looks like this:
const msg = {
to: process.env.EMAIL_TO,
from: process.env.EMAIL_FROM,
templateId: process.env.SENDGRID_TEMPLATE_ID,
dynamic_template_data: {
org_url: `${process.env.ORG_URL}/${key}`,
},
substitutions: {
'-org_url-': `${process.env.ORG_URL}/${key}`
}
};
Upon checking the sent email, the href field is either empty or only has -org_url- in it. How could I pass it the proper link? Thank you!
You can edit module html code and use string interpolation to insert the handlebar.
<a href=`{{shipperLoadUrl}}`>portal</a>
Assuming that you're using SendGrid's v3 API (which you are if you're using their Library), you need to make sure to pass the Substitution argument within the Personalization argument.
If you're not using the Library and are hand-building your call, you'll need to follow the full format, or implement the Library.

"Exception Occurred" with addSiteAccount1

After having gotten a site's login form from getSiteLoginForm, I'm attempting to add a site, but I'm receiving
{ :errorOccurred=>"true", :exceptionType=>"Exception Occurred", :referenceCode=>"_fa9ede97-1792-45ca-b147-005ec4002d33" }
The URL I'm POSTing to (in Rails) is:
https://consolidatedsdk.yodlee.com/yodsoap/srest/private-fairshare/v1.0/jsonsdk/SiteAccountManagement/addSiteAccount1
and this is the POST data:
cobSessionToken=REDACTED
userSessionToken=REDACTED
siteId=11671
credentialFields.enclosedType=com.yodlee.common.FieldInfoSingle
credentialFields[0][displayName]=User Name
credentialFields[0][fieldType.typeName]=TEXT
credentialFields[0][isEditable]=true
credentialFields[0][name]=LOGIN
credentialFields[0][value]=testuser
credentialFields[0][valueIdentifier]=LOGIN
credentialFields[0][valueMask]=LOGIN_FIELD
credentialFields[1][displayName]=Password
credentialFields[1][fieldType.typeName]=IF_PASSWORD
credentialFields[1][isEditable]=true
credentialFields[1][name]=PASSWORD
credentialFields[1][value]=testpass
credentialFields[1][valueIdentifier]=PASSWORD
credentialFields[1][valueMask]=LOGIN_FIELD
I've triple checked the parameters, and they seem to match up with the documentation.
Is there something I'm missing?
Looking at the documentation it looks like there's a mismatch in the format of your parameters.
For example, you have the field credentialFields[0][displayName], but in the documentation it's referred to as credentialFields[0].displayName. Is is possible that the API expects fields in this format?
If the API does expect fields in the credentialFields[0][displayName] then it would make sense for the credentialFields.enclosedType field to follow the same format. In that case it should be credentialFields[enclosedType].

Twitter API 1.1 - render twitter's t.co links

I want to display the tweets of an account in my website. The problem is that the tweets appear always with the format http://t.co/..., instead of the full link as desired by me.
For instance, I obtain:
the rules of the game are all implemented - local players can play together in this link: http://t.co/Nf7j4TaB
if you are very curious... then, here is the link to the xodul's section under development: http://t.co/6Zbti36T
etc...
and I want that these tweets appear like this:
the rules of the game are all implemented - local players can play together in this link: http://xodul.com/tests/js/
if you are very curious... then, here is the link to the xodul's section under development: http://xodul.com/tests
etc...
To make my application I've followed the instructions from:
Simplest PHP example for retrieving user_timeline with Twitter API version 1.1 (from here we can get the text of each tweet, with the links coming in the format: http://t.co/...)
Rendering links in tweet when using Get Statuses API 1.1 (the code of the highest scored answer, in this link replaces, for instance, the text "http://t.co/Nf7j4TaB" with the hyperlink "<a target='_blank' href='http://t.co/Nf7j4TaB'>http://t.co/Nf7j4TaB</a>")
I appreciate very much any help on how to render the twitter's links!
With the tutorial you followed you can use these attributes to show actual link.
Note: In API v1.1, entities will always be included unless you set include_entities to False or 0.
The urls entity
An array of URLs extracted from the Tweet text. Each URL entity comes with the following attributes:
url: The URL that was extracted
display_url: (only for t.co links) Not a URL but a string to display instead of the URL
expanded_url: (only for t.co links) The fully resolved URL
indices: The character positions the URL was extracted from
https://dev.twitter.com/docs/tweet-entities
JavaScript only solution for now to get Twitter posts on your site without using new 1.1 API and actually returns the full url in posts, not the twitter shortened version :-) http://goo.gl/JinwJ
Thank you for your answers.
After analyzing the JSON in the suggested link (https://dev.twitter.com/docs/tweet-entities), I wrote a solution to the exposed problem:
// ...
$twitter_data = json_decode($json); // last line of the code in: http://stackoverflow.com/questions/12916539
// print the tweets, with the full URLs:
foreach ($twitter_data as $item) {
$text = $item->text;
foreach ($item->entities->urls as $url) {
$text = str_replace($url->url, $url->expanded_url, $text);
}
echo $text . '<br /><br />';
// optionally, here, the code from: http://stackoverflow.com/questions/15610968/
// can be added, too.
}

Parse Facebook Feed Json Data

I want to parse a facebook feed.
Here is my json Url: http://www.facebook.com/feeds/page.php?id=199009743552420&format=json
So I got this type of Data in response:
"content": "\u003Ca href=\"\/l.php?u=http\u00253A\u00252F\u00252Fwww.youtube.com\u00252Fwatch\u00253Fv\u00253D9_PaHtaKAug\u002526list\u00253DPLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n\u002526index\u00253D1\u002526feature\u00253Dplpp_video&h=0AQEQfrMH&s=1\" id=\"\" title=\"\" target=\"\" onclick=\"LinkshimAsyncLink.swap(this, "\\\/l.php?u=http\\u00253A\\u00252F\\u00252Fwww.youtube.com\\u00252Fwatch\\u00253Fv\\u00253D9_PaHtaKAug\\u002526list\\u00253DPLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n\\u002526index\\u00253D1\\u002526feature\\u00253Dplpp_video&h=0AQEQfrMH&s=1");\" style=\"\" rel=\"nofollow\" onmouseover=\"LinkshimAsyncLink.swap(this, "http:\\\/\\\/www.youtube.com\\\/watch?v=9_PaHtaKAug&list=PLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n&index=1&feature=plpp_video");\">\u003Cimg class=\"img\" src=\"http:\/\/external.ak.fbcdn.net\/safe_image.php?d=AQDshpKwwDhCYH9k&w=130&h=130&url=http\u00253A\u00252F\u00252Fi2.ytimg.com\u00252Fvi\u00252F9_PaHtaKAug\u00252Fmqdefault.jpg\" alt=\"\" style=\"height:90px;\" \/>\u003C\/a>\u003Cbr\/>\u003Ca href=\"\/l.php?u=http\u00253A\u00252F\u00252Fwww.youtube.com\u00252Fwatch\u00253Fv\u00253D9_PaHtaKAug\u002526list\u00253DPLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n\u002526index\u00253D1\u002526feature\u00253Dplpp_video&h=PAQEzb06t&s=1\" id=\"\" target=\"_blank\" onclick=\"LinkshimAsyncLink.swap(this, "\\\/l.php?u=http\\u00253A\\u00252F\\u00252Fwww.youtube.com\\u00252Fwatch\\u00253Fv\\u00253D9_PaHtaKAug\\u002526list\\u00253DPLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n\\u002526index\\u00253D1\\u002526feature\\u00253Dplpp_video&h=PAQEzb06t&s=1");\" style=\"\" rel=\"nofollow\" onmouseover=\"LinkshimAsyncLink.swap(this, "http:\\\/\\\/www.youtube.com\\\/watch?v=9_PaHtaKAug&list=PLc4q0uG_h6x5tA_L3kHK6TE9TV6skf14n&index=1&feature=plpp_video");\">The Dissident Files - Ausama Monajed at THiNK 2012\u003C\/a>\u003Cbr\/>www.youtube.com\u003Cbr\/>Ausama Monajed in conversation with NDTV's Vishnu Som in Tehelka's THiNK 2012 session on "The Troubled Looking Glass: Why You Should Care About Syria" For mo... "
It contains image logo url, video url, .... so how can I parse this type of data?
Please help me.
Thanking You
Once you have the content field parsed from the json, you will need to parse it again keeping in mind that now you are dealing with html code. If you want to do some complex queries you will have to use XPath with the libxml2 library.
See: iOS: Best way to parse html tags?
If you only want to do a simple query, you can iterate over the string and picking what you want

How to Add Tag via Asana API

I am trying to do a simple Salesforce-Asana integration. I have many functions working, but I am having trouble with adding a tag to a workspace. Since I can't find documentation on the addTag method, I'm sort of guessing at what is required.
If I post the following JSON to https://app.asana.com/api/1.0/workspaces/WORKSPACEID/tasks:
{"data":{"name":"MyTagName","notes":"Test Notes"}}
The tag gets created in Asana, but with blank notes and name fields. If I try to get a bit more fancy and post:
{"data":{"name":"MyTagName","notes":"Test Notes","followers":[{"id":"MY_USER_ID"}]}}
I receive:
{"errors":[{"message":"Invalid field: {\"data\":{\"name\":\"MyTagName\",\"notes\":\"Test Notes\",\"followers\":[{\"id\":\"MY_USER_ID\"}]}}"}]}
I'm thinking the backslashes may mean that my request is being modified by the post, though debug output shows a properly formatted json string before the post.
Sample Code:
JSONGenerator jsongen = JSON.createGenerator(false);
jsongen.writeStartObject();
jsongen.writeFieldName('data');
jsongen.writeStartObject();
jsongen.writeStringField('name', 'MyTagName');
jsongen.writeStringField('notes', 'Test Notes');
jsongen.writeFieldName('followers');
jsongen.writeStartArray();
jsongen.writeStartObject();
jsongen.writeStringField('id', 'MY_USER_ID');
jsongen.writeEndObject();
jsongen.writeEndArray();
jsongen.writeEndObject();
jsongen.writeEndObject();
String requestbody = jsongen.getAsString();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://app.asana.com/api/1.0/workspaces/WORKSPACEID/tags');
req.setMethod('POST');
//===Auth header created here - working fine===
req.setBody(requestbody);
Http http = new Http();
HTTPResponse res = http.send(req);
return res.getBody();
Any help appreciated. I am inexperienced using JSON as well as the Asana API.
The problem was that I was posting to the wrong endpoint. Instead of workspaces/workspaceid/tags, I should have been using /tags and including workspaceid in the body of the request.
Aha, so you can add tags and even set followers despite the API not mentioning that you can or claiming that followers are read-only.
So to sum up for anyone else interested: POSTing to the endpoint https://app.asana.com/api/1.0/tags you can create a tag like this:
{ "data" : { "workspace": 1234567, "name" : "newtagname", "followers": [45678, 6789] } }
where 1234567 is your workspace ID and 45678 and 6789 are your new followers.
Since you posted this question, Asana's API and developer has introduced Tags. You documentation lays out the answer to your question pretty clearly:
https://asana.com/developers/api-reference/tags
I'm a bit confused by your question. Your ask "how to add a tag" but the first half of your question talks about adding a task. The problem with what you describe there is that you are trying to set a task's followers but the followers field is currently read-only according to Asana's API documentation. That is why you are getting an error. You can not set followers with the API right now.
The second part of your question - with the sample code - does look like you are trying to add a tag. However, right now the Asana API does not support this (at least according to the API documentation). You can update an existing tag but you can't add one.
So, to sum up: at this time the API does not allow you to add followers to a task or to create new tags.

Resources