Can I turn a message into a string? I've tried just using the variable message to do that but it doesn't seem to work. I've tried...
print(message)
and all it told me was the message id and sender, and not the raw text or content.
You're looking for message.content. Just printing out message will give you the attributes and such values that you'll have access to.
If you're planning on seeing the "clean" version of the content, if it has mentions of users or channels in it, you can instead use the message.clean_content attribute.
See the references for more info on the attributes of the Message object.
References:
Message.content
Message.clean_content
Related
in automate i have a flow. I am using "When keywords are mentioned". the keyword i entered is "test"
I Selected, the team,channel,etc... all correctly.
when someone types "the test is a success". in that channel. how do i get the full string "the test is a success"?
I have tried a few operations "get Messages", also tried a few dynamic content options and a few triggeroutput variations. all either are blank or provide a long json string with subscription,channelId,teamId,etc. but not the string I am trying to get.
The Get message details action should help you ...
In the body of the response, you'll clearly see the text that was entered to invoke the trigger.
Use Get message details, you will get message detail of that reply message. Then get your text with expression like this:
outputs('Get_message_details')?['body']['body']['plainTextContent']
query.edit_message_text(InputMediaDocument("https://t.me/aastuchem/125"))
TypeError: Object of type InputMediaDocument is not JSON serializable
You can't add a document to a text message that didn't have a document in it before. To edit the document in a message that does have a document in it, you'll have to use query.edit_message_media and note that providing a link to a telegram message doesn't work. See also this wiki entry.
Today, my bot stopped responding to me when clicking on quick replies in FB Messenger. Instead of getting the payload as a string, it now returns a stringified object with extra fields.
I'm using a bot with a custom dynamic dialog and creating SuggestedAction like this:
choices.push(builder.CardAction.postBack(session, "title=Name¶ms=Some", "Quick Reply Name"));
I used to receive the payload as a string "title=Name¶ms=Some" in Session object like the following:
session.message.text
But now, in session.message.text, I receive the following string:
"{\r\n \"type\": \"postBack\",\r\n \"value\": \"title=Name¶ms=Some\"\r\n}"
Has anybody else faced this same issue?
Is this coming from changes in Azure Bot Service? And if so, where can we follow the change log or release notes?
Since card action behavior is channel-specific it's much more likely that this relates to a change in the Facebook Messenger platform. You can view their changelog here: https://developers.facebook.com/docs/messenger-platform/changelog/
I can see there was a change on January 8th. It doesn't mention anything about postBack behavior, but it's still possible that there could be some unintended or undocumented changes that are responsible for the results you're seeing.
It looks like it should be a simple matter to deserialize the JSON and extract the value.
var payload = JSON.parse(session.message.text).value;
I am developing a series of Slack apps for my workspace, and some of them are meant to interact with the content (messages) delivered by the other apps : extracting content IDs that may be referred to by other messages
A concrete example :
Suppose I have an app A "FindUser" that is capable of giving me the user profile when a slack user types find me#example.com, and it replies in the thread with a formatted view of the user profile
I am developing an app B "EditTags", which basically gives me a right click option with "edit tags" (see Slack's Interactive Components/Actions), the idea being that a user could first ask app A to find a user, and then right click on the reply from App A and click the "edit tags" action given by the other app. What this app B does it actually retrieve the tags for the user mentionned by the previous message from app A, and in another reply to the thread it gives some controls to either delete an existing tag OR it shows a select with autocomplete to add new tags.
The B app needs to retrieve the user ID that the A app mentionned previously. So I need some way to pass that data directly in the slack message. When looking at the examples, slack does not seem to provide a way to add arbitrary "metadata" to a message, am I wrong ? Do you have workaround for this ? I mean I could totally send the user ID say, in the footer, so I can just read the footer, but I was planning to use the footer for something else... Is there a way to pass metadata hrough properties that would be hidden to the end user ?
Although this does not feel relevant, I am building a slack nodeJS app using the node slack sdk (and especially the #slack/interactive-messages package)
For the most part the Slack API does not provide any official means to attach custom data / meta data to messages. But with some simple "hacks" it is still possible. Here is how:
Approach
The basic approach is to use an existing field of the message as container for your data. Obviously you want to pick a field that is not directly linked to Slack functionality.
Some field are not always needed, so you can just use that field as data container. Or if its needed, you can include the functional value of that field along with your custom data in the data container.
For example for message buttons you could use the value field of a button and structure your code in a way that you do not need it in its original function. Usually its sufficient to know which button the user client (via the name field), so the value field is free to be used for your custom data. Or you can include the functional value of your button along with the custom data in a data container (e.g. a JSON string) in that field.
Serialization
All messages are transported through HTTP and mostly encoded as UTF-8 in JSON. So you want to serialize / de-serialize your data accordingly, especially if its binary data. If possible I would recommend to use JSON.
Length
The maximum allowed length of most fields is documented in the official Slack API documentation. e.g. for the value field for message buttons can contain up to 2.000 characters. Keep in mind that you need to consider the length of your data after serialization. e.g. if you convert binary data into Base64 so it can be transported with HTTP you will end up with about 1.33 characters for every byte.
Contents
In general I would recommend to keep your data container as small as possible and not include the actual data, but only IDs. Here are two common approaches:
Include IDs of your data objects and load the actual objects
from a data store when the request is later processed.
Include the ID of server session and when processing the request you
can restore the corresponding server session which contains all data
objects.
In addition you might need to include functional values so that the functionality of the field you are using still works (e.g. value of a menu option, see below)
Implementation
Dialogs
Dialogs provide an official field for custom data called state. Up to 3.000 characters.
Message buttons
For Message buttons you can use the message action fields / value. Up to 2.000 characters. Its also possible to use the name field, but I would advise against it, because the maximum allowed length of that field is not documented.
Message menus
For Message menus you can use the value field of an option or the name field of the menu action.
Usually the value field is the better approach, since you have a documented max length of 2.000 and it gives you more flexibility. However, you will need to combine you custom data with the actual functional value for each option. Also, this will not work for dynamic select elements (like users), where you can not control the value field.
When using the name field note, keep in mind that the maximum allowed length of name is not documented, so you want to keep you data as short as possible. Also, if you want to use more than one menu per attachment you need to include the actual name of the menu into your data container.
Normal message attachments
Normal message attachments do not contain any suitable field to be used as container for custom data, since all fields are linked to Slack functionality.
Technically you could use the fallback field, but only if you are 100% sure that your app is never used on a client that can not display attachments. Otherwise your data will be displayed to the user.
Sometimes, a web site/app needs to display multiple messages to the user following a request. Unfortunately, Yesod's message facility (if I understand well the docs) seems to be limited to a single message per request, with each new message overwriting the previous one. I thought that I could use a writer monad inside the handler to get around this, rendering the message list to HTML before saving it with 'setMessage', but being fairly new to Haskell, I don't have a clue how to integrate an additional monad to the handler's type signature (in fact, I'm not even sure whether this is feasible or not). So, I would like to know what is the recommended approach for multiple session messages in Yesod? Thanks.
You read the book correctly, you can have only one message. But you can display any HTML in that message. You can use blaze-html to generate a message with any HTML that you want.
This snippet does just that:
import Text.Blaze.Html5
-- Create a message.
message :: Html
message = do
p "Welcome to my site"
p "Your account was created successfully"
-- Use the message in your handler.
getHomeR :: Handler Html
getHomeR = defaultLayout $ do
setTitle "Yesod Web Service Homepage"
setMessage $ message
$(widgetFile "home")
To the user of your home page it will be like you have two messages. To learn more about blaze-html take a look here.