Slack API: How to reply for an attachment action? - api

I've created an integration with Slack as a WebHook APP. The code is to send a message to a slack channel, using the chat.postMessage method, with some attachment actions, then when the user click the action button, I send him a success message. I'm trying to do something like this:
https://api.slack.com/img/api/message_guidelines/Example_6.gif
The problem is when I try to send the success message. Slack is receiving only the text part of the answer. Here is the code:
$message = 'Pre-text message';
$attachments = array(
array(
"title" => 'Title message',
"author_name" => 'My name',
"author_link" => 'https://www.facebook.com/',
"author_icon" => 'https://graph.facebook.com/v2.6/picture',
"image_url" => 'https://i.scdn.co/image',
),
);
$answer = array(
'text' => $message,
'attachments' => json_encode($attachments)
)
How can I do to Slack show the answer with the attachment part as shown in the image above? If I comment the text part on $answer, Slack show an error to user ('Oh no, something went wrong. Please try that again.'). Many thanks for any help.

I found the solution. Posting here to help somebody with the same problem. When you posting a message, should json_encode the attachment part, but when posting the attachment action answer, is not necessary. Here is the solution:
$message = 'Pre-text message';
$attachments = array(
array(
"title" => 'Title message',
"author_name" => 'My name',
"author_link" => 'https://www.facebook.com/',
"author_icon" => 'https://graph.facebook.com/v2.6/picture',
"image_url" => 'https://i.scdn.co/image',
),
);
$answer = array(
'text' => $message,
'attachments' => $attachments
)

Related

Is it possible to send a keyboard without sending text or a message at telegram

I try to send and delete the message but not working
if($new = $bot->sendMessage([
'chat_id' => $call_chat_id,
'text' => ' ',
'parse_mode' => 'HTML',
'reply_markup' => $choose,
])){
$bot->deleteMessage([
'chat_id' => $chat_id,
'message_id' => $new['message_id']
]);
}
am using Telegram-bot-simple
No there is no way to send keyboard without sending a message

Mollie applicationfee's

for a customer I need to charge an applicationFee for each order that has been processed on their site from the sub customers. The whole code is working with authentication and everything.
But from the moment I'm adding:
'applicationFee' => $applicationFee
to the call I receive this error:
Error executing API call (422: Unprocessable Entity): Unable to process application request for this account. Documentation: https://docs.mollie.com/guides/handling-errors"
The content of "$applicationFee" is correct, that I was able to check already.
The $shop_mollie_data->profile_id containts the different websiteprofileId's found on the Mollie dashboard.
$provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
$newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);
$mollie = new MollieApiClient();
$mollie->setAccessToken($newAccessToken['access_token']);
$payment = $mollie->payments->create([
'amount' => [
'currency' => 'EUR',
'value' => (string) (sprintf("%.2f", $order_total))
],
'description' => ucfirst($shop->name) . ' - Order #' . $order_nm,
'webhookUrl' => $url_callback,
'redirectUrl' => $url_success,
'method' => 'bancontact',
'locale' => $language_id,
'metadata' => [
"order_id" => $ref,
"shop id" => $shop->id
],
'profileId' => $shop_mollie_data->profile_id,
'testmode' => true,
'applicationFee' => $applicationFee
]);

Mandrill's UNSUB merge tag not getting parsed

I'm trying to make it so when someone clicks on the unsubscribe link in an email sent via the Mandrill API (using PHP) it works as described in: http://help.mandrill.com/entries/23815367-Can-I-add-an-automatic-unsubscribe-link-to-Mandrill-emails-
The *|UNSUB|* merge tag is not getting parsed. It just comes through in the the body of the email received.
Near the end of the message content ($message_content) I have:
Click here to unsubscribe.
In Gmail, the link is: Click here to unsubscribe.
(NOT a valid HREF, so Gmail just ignores the anchor tag)
In Outlook 2010 the link is: Click here to unsubscribe.
(Not a valid HREF)
Is there some merge_vars parameter I should add to the headers?
http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content- mentions them, but I can't find what the parameter should be for the UNSUB merge tag.
$mandrill = new Mandrill($mandrill_api_key);
$message = array(
'html' => $message_content,
'subject' => $subject,
'from_email' => 'me#mydomain.com',
'from_name' => 'MY NAME',
'to' => $to_list,
'headers' => array('Reply-To' => 'me#mydomain.com'),
'important' => false,
'track_opens' => 1,
'track_clicks' => null,
'auto_text' => null,
'auto_html' => null,
'inline_css' => null,
'url_strip_qs' => null,
'preserve_recipients' => 0,
'view_content_link' => 1,
'tracking_domain' => null,
'signing_domain' => null,
'return_path_domain' => null,
'merge' => true,
'global_merge_vars' => array(
array(
'unsub' => 'unsub'
)
),
);
What step am I missing?
TIA!
The problem was the URL was missing a slash (http:/mydomain...)
This was caused by TinyMCE converting URLs. I added convert_urls: false to the tinymce.init and that solved my problem.
Kudos to Mandrill Support for helping me identify the problem.

How can I sent relevant email by using Amazon SES?

I am using Amazon SES server for sending notifications emails to my users. I have verified email and verified domain. So SES_Client is sending emails successfully.
Here is my code:
public function send($subject, $recipients, $body, $senderName){
$response = $this->SESClient->send_email(
$senderName.'-noreply#example.com',
array(
'ToAddresses' => $recipients
),
array(
'Subject' => array(
'Data' => $subject,
'Charset' => 'UTF-8'
),
'Body' => array(
'Text' => array(
'Data' => $body,
'Charset' => 'UTF-8'
),
'Html' => array(
'Data' => $body,
'Charset' => 'UTF-8'
)
)
)
);
return $response->isOK();
}
Problem:
How can I pass parameters values in email text that are belongs to individual recipient in recipients array?
Is there a way at amazon server where I can create queue of my recipients and when SES server will send my email. It will replace all parameters values that belongs to each recipient.
The ToAddresses field should be an array.
Is there a way at amazon server where I can create queue of my recipients and when SES server will send my email. It will replace all parameters values that belongs to each recipient.
No, AWS and the SES service does not currently support this.

YouTube API Upload Video as 'Unlisted' or 'Private'?

I am using a Wordpress plugin called 'YouTube Uploader', it allows you to upload YouTube videos from your WordPress site, it is working for me but the only issue is that it uploads the videos as Public and I need them to go up as Unlisted or Private (either will do). If someone could tell me what to add/change to make it do this, it would be greatly appreciated, thanks!
I uploaded the code to Pastebin as I didn't want to fill this entire post with code, heres the link: http://pastebin.com/GfQjhiiq
Thanks!
I'm not that clued up on Wordpress but what you're looking for is a tag called <yt:private/>
<yt:private/> is a child of media:group so a sample xml schema could look something like the following. (Note where <yt:private/> sits within the code block):
<media:group>
<media:title type="plain">Title here</media:title>
<media:description type="plain">Description here</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel</media:category>
<media:keywords>keyword1</media:keywords>
<yt:private/>
</media:group>
Hope this is of some use.
I think this method is pretty outdated. But there is a work around if you were to use the the Plain PHP API method...
This Part does the trick:
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
In the bigger scheme:
$this->Zend->loadClass('Zend_Gdata_ClientLogin');
$this->Zend->loadClass('Zend_Gdata_YouTube');
$client = Zend_Gdata_ClientLogin::getHttpClient(ZEND_GDATA_CLIENT_EMAIL, ZEND_GDATA_CLIENT_PASS, 'youtube');
$client->setHeaders('X-GData-Key', "key=".ZEND_GDATA_YOUTUBE_DEVELOPER_KEY);
$yt = new Zend_Gdata_YouTube($client);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Sports');
The whole Gist is over here: https://gist.github.com/1044349