How to configure slash command response to entire channel? - php

I'm currently using the "Isitup" slack slash command example authored by David McCreath (more here": https://github.com/mccreath/isitup-for-slack/blob/master/isitup.php).
Within this code, I am wondering how I would go about making the response go from appearing "only to me" to posting in to the entire channel, along with the query posted by the user. I've read the slack documentation which shows the "in_channel" parameter that needs to be added, however I am just not that strong with code so I'm really not sure where I should input this in to the code I've got.
I'm sure this is a simple fix - can someone provide assistance? I've searched everywhere and can't seem to find a comprehensive answer.

As you correctly mentioned the trick is to reply to Slack by setting the property response_type to in_channel.
The current code (as per your github link) is replaying to Slack with a simple plain text in the following line:
echo $reply;
In order to set the response_type property it needs to reply with a JSON array instead that should look like this:
{
"response_type": "in_channel",
"text": "It's 80 degrees right now."
}
All you need to do is build a PHP array with those two properties, convert it to JSON with json_encode() and send it back to Slack instead of the plain text.

Related

Trying to make a basic slash command response in Slack

I currently have a basic slash command integration where I simply want people to be able to type /Slashcommandname and then any text string thereafter, and have the slash command return a simple text string (i.e. "Hello world!") in the channel. This should be public facing, not just ephemeral.
I can't for the life of me figure out how to write a basic PHP script to do this, despite all the reading of tutorials I have done online on these matters. Can someone assist? I've been successful in simply echoing some text but can't get the in_channel function working correctly.

Why do I get random text appended to my STOMP protocol messages?

I'm having an issue where I'm able to write many json encoded arrays to HornetQ without any problem, but when I try to read the frames back, every n'th message has random text appended to it (usually MESSAGE or RECEIPT).
Example:
I send the following to HornetQ:
{"data":9933753,"more_data":"Some Text"}
and I get back the following when I read the frame body:
{"data":9933753,"more_data":"Some Text"}
MESSAGE subscription:subscription/jms.queue.testing.qa.myqueue message-id:1310
destination:jms.queue.testing.qa.myqueue expires:0 redelivered:false priority:4 timestamp:1382637077839
I read the STOMP protocol definition and I still don't get how I can get back just the json string that I sent without the extra text seeing as the MESSAGE is in the body itself (making it impossible to decode it back without doing hacky string manipulations).
I have the following setup:
HornetQ (latest)
PHP 5.4
STOMP library: http://stomp.fusesource.org/documentation/php/book.html
Any suggestions are appreciated!
It's a bug probably. there was a fix around that at some point as I remember. If you are still seeing it with the latest version you have to provide a testcase to the developers and we would gladly fix it. I'm speaking here as one of the developers.
But first check if you are on the latest version. (2.3.0+ or 2.4.0 beta), or any latest EAP version.

Some markup mysteriously goes missing when send to server using ajax (POST) as string

OS: Windows 7 (64-Bit)WAMP Version: 2.2Apache Version: 2.2.22PHP
Version: 5.4.3Framework: CodeIgniter 2.1.2
Hi, I am experiencing something strange, and can't seem to pinpoint the cause. I am sending a js object to server to be saved in db in BLOB. The object is converted to JSON string using JSON.stringify() before sending it in Ajax(POST) call.
Object After Using JSON.stringify
[{"page_id":"1","site_id":456,"composite_id":"456-1-text-1","type":"2","properties":"{\"id\":\"text-1\",\"isModified\":false,\"isNew\":false,\"name\":\"Text 1\",\"content\":\"<span style=\\\"text-decoration:underline;font-size:x-large;color:#7092be;background-color:#c8bfe7;\\\"><strong>Your text here</strong></span>\",\"keywords\":\"\",\"top\":103,\"left\":119,\"width\":130,\"height\":30,\"style\":{\"borderColor\":\"#1e07da\",\"borderSize\":\"2\",\"borderRadius\":\"6\",\"shadowType\":\"drop-shadow\",\"shadowColor\":\"#000000\",\"shadowSize\":\"0\",\"shadowBlur\":\"0\",\"boxShadowColor\":\"#000000\",\"boxShadowPosX\":\"3\",\"boxShadowPosY\":\"2\",\"boxShadowBlur\":\"5\",\"boxShadowType\":\"\",\"zIndex\":2020}}"}]
This is the concerning part from above string that gets modified(Key-Value Pair):
\"content\":\"<span style=\\\"text-decoration:underline;font-size:x-large;color:#7092be;background-color:#c8bfe7;\\\"><strong>Your text here</strong></span>\"
I send this string to api controller using ajax. When I receive it in the controller I use print_r() to print the variable. But now insted of the above mentioned part this is what I receive:
[{"page_id":"1","site_id":456,"composite_id":"456-1-text-1","type":"2","properties":"{\"id\":\"text-1\",\"isModified\":false,\"isNew\":false,\"name\":\"Text 1\",\"content\":\"<span ><strong><em>Your text here</em></strong></span>\",\"keywords\":\"\",\"top\":103,\"left\":119,\"width\":130,\"height\":30,\"style\":{\"borderColor\":\"#1e07da\",\"borderSize\":\"2\",\"borderRadius\":\"6\",\"shadowType\":\"drop-shadow\",\"shadowColor\":\"#000000\",\"shadowSize\":\"0\",\"shadowBlur\":\"0\",\"boxShadowColor\":\"#000000\",\"boxShadowPosX\":\"3\",\"boxShadowPosY\":\"2\",\"boxShadowBlur\":\"5\",\"boxShadowType\":\"\",\"zIndex\":2020}}"}]
As you can see the concerned part is missing the style settings and is now modified to:
\"content\":\"<span ><strong><em>Your text here</em></strong></span>\"
I have been searching it over the internet, but it does not seem to be a common problem as I cant find anything related to it. So now I am counting on SO.
Regards
UPDATE:
I used var_dump($_REQUEST)as suggested by #BogdanBurim. And this is the concerned part:
\"content\":\"<span style=\\\"text-decoration:underline;font-size:x-large;color:#7092be;background-color:#c8bfe7;\\\"><strong>Your text here</strong></span>\"
As you can see the style settings are still there. So with we come to the decision that CI filters might be removing this part from string. So now the question is how to fix this issue?
Well after discussion with #BogdanBurim, I came to conclusion that to avoid XSS to some extent CI removed any text included within quotes and double quotes, from data sent to server.
There was an option to extend CI_Input library to allow selective disabling of XSS filter. That would solve my issue but would raise security concerns. So instead what I did is I encode (base_64) the data before sending it to the api. It is saved in DB as BLOB. And when fetched is decoded on client side.

php curl for facebook post tweet

I want post tweets into facebook using php curl , this is my snippet I used for posting tweet into FB - FB CURL SNIPPET
But i am not find any updated tweet in my facebook,
am not sure but i thing somthing goes wrong,
Can you tell me, snippet is correct one or not?
Thanks
This calls for debugging.
First port of call: It could be that the cookies are not saved: Check whether the script actually generates a my_cookies.txt file. If it doesn't, create an empty one and do a chmod 777 on it.
Second port of call: curl_error().
Replace every curl_exec() call in the snippet by this:
$success = curl_exec(....... your options .....);
if (!$success) echo "CURL Error: ".curl_error();
this might give you some pointers as to what goes wrong.
However, seeing as the script tries to imitate a browser instead of using an API, it could be that the structure of the submission form has changed on Facebooks's side, in which case you'll have to parse the output cURL gives you and see what goes wrong.
All in all, if there is any way to do this cleanly through an API - I don't know whether there is - it would be much preferable to this.

Post to twitter help - using php

I am trying to post a url to twitter but the url is user generated and dynamic...
TWEET THIS REQUEST
i started with that but its not catching the actual url- then i tried a few others but they seem to be for static urls
do i have to use the api or is there a way for this urlencode to read the specific url we want the users to publish?
thanks
UPDATE
TWEET THIS REQUEST
<p> <img target="Borrow this from someone on twitter" src="PHOTOBUCKET direct URL HERE" alt="TWEET THIS (IMPROVE YOUR SELECTION)" title="" border="0" /></p>
basically i want a combination of both- if you see "item=22" that is always changing- so i want a button where the code will actually read the CURRENT url not just a static one i added at the beginning... is this possible?
probably something like this?
<?php
$posts = array (
'i\'d like to borrow this item #neighborrow',
'test this very carefully',
'enough!!!'
);
foreach( $posts as $post )
{
?>
tweet this request <small>[<?php echo $post; ?>]</small> <br/>
<?php
}
?>
Liveview at codecookie.net
hope i understood it correct!
There's a pretty handy PHP Twitter API library here: http://lab.arc90.com/2008/06/03/php-twitter-api-client/
That'll make sure you don't have to solve problems that have already been solved and you can concentrate on writing your code.
I think a problem might be that you used "[ ]" the square brackets to surround the string, and you ended it with a period.
Other than that, I might suggest using something like htmlentities () or htmlspecialchars().
Alternatively, you might want to look into using the API to do this. For one thing, unless you're checking somewhere else, there's no way to guarantee the user is signed into twitter, and the API allows you to authenticate with twitter, plus the API is more likely to be supported longer than the query string request.
UPDATE:
I think the problem would be in this part of the code:
TWEET THIS REQUEST
You call a function called urlencode, but it's in the HTML part of the code, so the PHP is not going to execute that function, and the HTML simply parses it as plain text.
You'd want to replace it with this:
TWEET THIS REQUEST
That should let the php code parse that and return the encoded string.

Categories