Hide Text Sent via Post Activity Event - reactjs

I'm currently sending a text programmatically to my bot following the article on https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/d.post-activity-event
Everything is working fine but I want to hide the text being sent so that the user does not see it on the session. Is this possible to do?

Instead of initializing and using the useSendMessage hook, replace it with useSendPostBack. Using useSendPostBack will generate a postBack message activity which simply sends a value back to the bot without displaying it to the user. The value sent to the bot should be located in the value property of the associated activity.
const sendPostBack = useSendPostBack();
const handleHelpButtonClick = useCallback(() => sendPostBack('help'), [sendMessage]);
A complete list of available hooks can be reviewed in the Web Chat repo doc, hooks.

Related

Store data in discord message for button component

I want to make a simple bot that does some things when someone clicks a list item.
To make this possible I need to store the list item's id in the message. I didn't see any ways to store data in a message without showing it, so I added it to the footer and when the button triggers it gets the first embed's footer in the interaction's message.
My problem with this solution is that it looks bad.
Collectors are not an option because these list items are sent to a channel once when the channel is created, and if the bot restarts the collectors won't trigger.
How would you guys solve this?
Thanks!
Okay I solved this. I don't know how I've never thought of this before.
Basically I created a table in my database that has 2 columns:
discord message id
data
When I send the message to the channel I just store the data with the message's id. When the user clicks the button I just retrieve the data by the message id.

Discord.js Animated Emojis

I have a bot, and I want to use it to send a animated emoji.
I have the emoji ID, <:rgb_lego:993606148580184154>
but whenever I make it send the message, it just says
Pong! 🏓 The round trip took 76ms. ⚡:rgb_lego:
what am I doing wrong?
It depends on what server (guild) you sent it and how exactly you do it.
Guess you need to check & fetch the requested custom emojie from server and then sent it.
You might wanna check Discord.js docs for that. But if I remember it correctly, emojies should be accessed by bot via:
client.guild.emojis.[methodName] via GuildEmojiManager
The second problem could be relevant to the server, where you want to sent it, doesn't have the required emojie, so in that case it has been delivered as a text ref, not an emojie itself or the bot account doesn't have premium features required for using emojies or so on.

How do I 'await' information from a modal?

I have a codesandbox for this question: https://codesandbox.io/s/chakra-modal-input-forked-jelhlr?file=/src/App.jsx
I want to get the filename via the modal, and when the user completes that action, I want to do stuff with that information, in this case I want to make an api request.
Thanks!
EDIT:
I have a form with the following onSubmit:
// 1. prepare data for POST request
const data=prepareData();
// 2. get title for data entry from user
onOpen();
// 3. send data via POST request
const response=await axios.post('route',{title,data})
The way things are, the modal shows at step 2 and without waiting for user input, step 3 occurs. I want to get the title name from the user and then I want step 3 to occur.
I found the package react-modal-promise that does exact this. Works perfectly!
The value of the textbook is saved into the ref titleInputRef.
This means you can access the value of the ref/textbox with the following:
titleInputRef.current.value
To log the value to the console, for example:
console.log(titleInputRef.current.value)

Reflect live updae of API in UI without refreshing screen

I am making a web app in which I have a section which has an input field. Anything that is submitted through the input field gets posted to an API. So when you land on that screen you see all the previous inputs made. What I am not able to figure out is and the thing I want to achieve is that when someone submits a new input it doesn't reflect in UI until and unless you go back and come back to the screen. I want that as soon as you send an input the input string should be reflected in the UI. How can this be done using AngularJS?
You have two options, at a very basic level they are:
1) The first is to re-query all the list when the item is saved:
api.save(newPost).then(() => getAllPosts());
2) You can return the recently saved post and add it to the list:
api.save(newPost).then((saved) => $scope.posts.push(saved));
You'll need to handle all the unwrapping (etc) based on how you're making the calls.

How to modify firebase database so that i can set a read or unread status

I need to show the count of unread messages from firebase in the notification bell.
I am done with displaying all contents in my collection in my web application.But when a new message arrives i need to give a feedback to user by showing the unread message count in notification bell .From my understanding,for that i need to set a read/unread status in firebase collection.Is there any alternative way for showing the count of unread messages in my React Web Application?
i am using firebase package of npm for displaying messages.
Below is the sample data in my firebase collection.
name:"John Doe",
message:"you got a new appointment"
i am new to firebase.Please help me with some logic to sort out this problem.
If I understand correctly, you would want to use a status flag (read: boolean), unless you would not mind writing all new messages to a particular path and moving them to another path after it is read.
Something like below
/user/unread-msg => all new messages come here
/user/read-msg => messages are moved here after being read.
This I believe would be less efficient than using a simple flag.
You could use a firebase cloud function to maintain the count of child elements in a particular path like /user/unread-msg or /user/read-msg so that you don't have to download the entire data to get the count.
Refer the sample code at https://github.com/firebase/functions-samples/tree/master/child-count

Resources