While creating a chatbot using AWS Lex, I would like to provide the response in hyperlink format. But I don't want to use Response card in this case. As per the AWS Lex docs, I knew that hyperlinks can't be given directly in responses. Am new to Lamda functions and tried with the following.
exports.handler = (event, context, callback) => {
callback(null, {
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "CustomPayload",
"content": "my link"
}
}
});
};
but still am getting the result in text format. Am even okay with any other approaches.
You can send URL's (no HTML tags) in the response as a normal message. But how that URL is displayed to the user depends on the channel you are using and their output formatting of that message.
I know that Facebook Messenger will automatically change a URL string to be a link. Most of the other channels probably do too. But the Lex Test Chat will not.
For testing this sort of thing, it is best to do it in the actual channel your Lex bot will use because a lot of formatting like this works in the actual channel but does not work in the Test Chat.
Related
I'm using Postman app to interact with a Telegram bot api. I've sent photos using the sendPhoto() method, like this:
https://api.telegram.org/botToken/sendPhoto?chat_id=00000000&photo=AgAC***rgehrehrhrn
But I don't understand the sendMediaGroup() method. Can someone post an example how to compose the https string to send two photos?
Thanks
You need to send a POST request at the url https://api.telegram.org/botToken/sendPhoto with a JSON body. You are using the url to specify all the parameters of the request but urls are only 2000 characters long. The body of a POST request, instead, has no limits in terms of size. The JSON body should look something like this:
{
"chat_id": 777000,
"media": [
{
"type": "photo",
"media": "https://example.com/first_photo_url.png",
"caption": "an optional description of the first photo",
"parse_mode": "optional (you can delete this parameter) the parse mode of the caption"
},
{
"type": "photo",
"media": "https://example.com/fsecond_photo_url.png",
"caption": "an optional description of the second photo",
"parse_mode": "optional (you can delete this parameter) the parse mode of the caption"
}
],
}
For more info see:
how to send JSON (raw) data with Postman
and
sendMediaGroup Telegram API's method.
You must send JSON as a string, or serialized JSON, to Telegram API. The format is as same as #GioIacca9's answer.
Note: only the caption in the first image will be showen.
Have a try this Python code.
def send_photos(api_key, chat_id, photo_paths):
params = {
'chat_id': chat_id,
'media': [],
}
for path in photo_paths:
params['media'].append({'type': 'photo', 'media': path})
params['media'] = json.dumps(params['media'])
url = f'https://api.telegram.org/bot{api_key}/sendMediaGroup'
return requests.post(url, data=params)
if __name__ == '__main__':
send_photos('your_key', '#yourchannel', ['http://your.image.one', 'http://your.image.two'])
I am working on integrating GMB into some of our internal apps, and would like to set up to receive real-time notifications for reviews and questions.
I have created a topic, and a subscription with a valid URL.
The next step is to tell GMB to send the notifications to the topic, and I believe the endpoint is the one below. However, it is very vague about the parameters it wants.
This is the documentation
https://developers.google.com/my-business/reference/rest/v4/accounts/updateNotifications
It wants a "Notification Settings Resource Name" in the URL, but it's not explained anywhere what that actually is. I have tried every possible value, but always get a 404 error response with the message "Requested entity was not found."
Has anyone successfully set this up? What values does the "getNotifications" endpoint want, and where in the various dashboards can this be found or created?
Any help is much appreciated!
As mentioned in the comments, you need to send the accountId as part of the URL.
To find this, you will first need to send a GET request to
https://mybusiness.googleapis.com/v4/accounts
This will return something along the following lines:
{
"accounts": [
{
"name": "accounts/102647145453118950380",
"accountName": "Tom Spencer",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED",
"vettedStatus": "NOT_VETTED"
},
"profilePhotoUrl": "//lh3.googleusercontent.com/a-/AOh14GgPkuJj03DeCa1isBAJALY4eOl09WGYVFrM4mG5=s132"
},
]
}
You can see here that accounts/102647145453118950380 is returned in the name field. Take this field, and construct the following URL:
https://mybusiness.googleapis.com/v4/accounts/102647145453118950380/notifications
Send a PUT request to this URL, with a request body resembling the following:
{
"topicName": "projects/{projectId}/topics/{topicId}",
"notificationTypes": [
"NEW_REVIEW",
"UPDATED_REVIEW"
]
}
Assuming you have pub/sub setup as per the documentation, this should send a message to your topic/subscribers whenever a new review is created or a review is updated.
I am trying send an image from POSTMAN. I am able to send a message but image is not getting posted.
https://slack.com/api/chat.postMessage
Used POST type headers i am passing token, channel and i have an Image URL but not sure how to send that. Can anyone please help me on this.
There are two alternative approaches on how to send your message to the API endpoint chat.postMessage:
Body as form-urlencoded
Here is how to include an image in a message send as x-www-form-urlencoded:
The image has to be send as part of an attachment by setting the property called image_url.
The attachments are set with the attachments key in the API call, which requires you define your attachments as array of attachment object in JSON.
In addition to the image_url your attachment needs to contain a fallback property, which is used to display a text to the user in case the image can not be displayed.
Your attachments object then looks like this in JSON:
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
Now you have to put that into an array (by adding [] around it) and this is what you get as value for your attachments key:
[{"fallback":"did not work","image_url":"https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"}]
In addition you need to add the keys token, channel, text key to your message. Voila.
Body as JSON
An alternative and probably easier approach is to send your data as JSON instead of x-www-form-urlencoded to the API.
This requires you to send the token in the Auth header and switch to JSON for the body.
To do that in Postman put your token as "Bearer Token" under "Authorization".
In "Body" switch to "raw" and select "JSON".
Then you can define the whole message as follows:
{
"channel": "test",
"text": "Hi there!",
"attachments":
[
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
]
}
Of course you can do the same in your code. Since your are working in JavaScript using JSON would be the natural approach.
Note that not all API methods support sending the body in JSON. Check out this documentation for more info.
I created a bot in AWS Lex and I am trying to integrate it with Slack. I created a Slack app and followed the documentation as mentioned in-
https://docs.aws.amazon.com/lex/latest/dg/slack-bot-association.html
However, while trying to integrate with the Lex Postback URL I get an error saying
Your URL didn't respond with the value of the challenge parameter.
Our Request:
POST
"body": {
"type": "url_verification",
"token": "VbODUleNdk2hieCvDwlScrQF",
"challenge": "HRUXnK6YYLpx5U1s9AiADZgA0BAhWuTzfjAAzLEJIw1zz4GfuMAb"
}
Your Response:
"code": 200
"error": "challenge_failed"
"body": {
}
Per my knowledge, Lex by default should provide the response. Am I doing something wrong here? Any leads will help.
Thanks in advance.
I encountered this this morning and I thought I'd add my own experience. Slack appears to be pushing a 'Verification Token' as a replacement for the 'Signing Key', and claims they're interchangeable but that the token is more secure. I wasn't able to get the challenge response when using the token, but it worked fine when using the key.
Came across the same issue. The POST request that Slack was sending my endpoint was not what my function was designed for. I followed the tutorial at https://api.slack.com/tutorials/events-api-using-aws-lambda and had to add a line:
exports.handler = (data, context, callback) => {
data = JSON.parse(data.body); // added this line
switch (data.type) {
case "url_verification": verify(data, callback); break;
case "event_callback": process(data.event, callback); break;
default: callback(null);
}
};
I'm trying to trigger Email using SES and API gateway without using Lambda function. It will contain pdf file and text. I'm able to trigger Email using QueryString parameters, but as i need to send files also I want to map from the body. Tried body mapping in API-gateway as below,
BODY MAPPING TEMPLATE
{
'Destination': {
ToAddresses:'xxxx#example.com'
},
'Message': {
'Body': {
'Text': {
'Data': 'message body ! hurray !!!',
'Charset': 'UTF-8'
}
},
'Subject': {
'Data': 'subject data',
'Charset': 'UTF-8'
}
},
'Source': 'yyy#example.com'
}
RESPONSE FROM SES
`{
"Output": {
"__type": "com.amazon.coral.service#SerializationException",
"Message": null
},
"Version": "1.0"
}`
Questions
Is it possible to achieve this without using lambda?
Am I using the body mapping correctly?
Could anyone please throw light on how to achieve this? Any help highly appreciated.
I got stuck on the same problem and finally made it. I'll share what I learned.
According to this document, request body should be in form of x-www-form-urlencoded, such as:
Action=SendRawEmail
&Destinations.member.1=allan%40example.com
&RawMessage.Data=RnJvbTp1c2VyQGV4YW1wbGUuY29tDQpTdWJqZWN0OiBUZXN0DQoNCk1lc3 ...
Also you have to set Content-Type:application/x-www-form-urlencoded header. If not, it causes exception. With this header, you can't send request with query parameter(since it includes ?) , you also have to set "Action Type" to "Use path override" and "/" in Integration Request section of API gateway console.
I also confirmed that I could send email with attachments using SendRawEmail action.
So my answer to original questions:
Is it possible to achieve this without using lambda? => Yes!
Am I using the body mapping correctly? => No, you have to use x-www-form-urelencoded request body.
Hope this will help.