How to store user messages without losing markup in telegram bots? - telegram

How do I store user messages without losing markup (HTML or Markdown) in the Telegram bots?
I'm working with node_telegram_bot_api
It's clear when sending a message from the bot to the user: specify parse_mode and everything is fine.
await bot.sendMessage(chatId, message, {reply_markup: JSON.stringify({inline_keyboard: keyboard}), parse_mode: 'HTML'});
But how to process messages with user markup and then store them in a database, for example, without losing the markup?

Related

Furnishing user data in NextAuth EmailProvider and Fauna DB on signIn

I'm using NextAuth's EmailProvider and FaunaAdapter with a FaunaDB instance to authenticate users in my NextJS application. I'm going down the "passwordless" route with this site, and the magic links are setup nicely after finishing the bulk of this tutorial.
There are some changes I've made to it, however, as I don't want a Sign Up page, and instead want only whitelisted emails that exist in my DB to be sent links to authenticate. I've done this by hijacking the signIn callback like so:
async signIn ({ user, account, profile, email, credentials }) {
// As "signIn" gets called twice when using magic links (once for sending and once for authenticating),
// we need to check here if this is a request for a magic link, as opposed to authenticating a token.
if (email.verificationRequest) {
// This is a helper function which does a lookup for the email in the "accounts"
// table of my Fauna DB.
return checkUserEmailExistsInAccounts(account.userId)
}
return true
}
This works nicely, but I wonder if it could be improved. I want any page that is behind the authentication wall to effectively have a session or JWT token that describes the user in more detail. If, say, I want the user name to be added to the session data, I then need to somehow modify the session or jwt callbacks to add this data. But that will involve yet another call to the database, where I have already made a perfectly useful call in the signIn process. Whats more, these callbacks are made frequently - whereas the signIn callback is only made a couple of times during the authentication process.
To summarise: how can I leverage a magic link sign-in system with NextAuth where I look up allowed emails from a pre-existing Fauna accounts collection, furnish a user object with the account data and have the account data become available to every page without needing further lookups when already-authenticated?
Edit: Just a note to say that when I first started playing with the library, I was surprised that simply putting the data into my accounts collection in Fauna DB didn't somehow magically make it appear in the session info. Perhaps I am not using the Fauna Adapter correctly, and this is actually the better way to go?

Delete/Edite a client message in private Chat with Telegram Bots

In private chat with a bot (a user and a Bot), is it possible to edit/delete user messages? I am creating a Telegram Bot for registration. As a registration step, the users insert their password, and for security considerations, I want to replace it with stars or delete it. Any idea?
It is as simple as calling deleteMessage with chat_id and message_id
https://core.telegram.org/bots/api#deletemessage
EDIT:
As #mohamad-mehdi-rajaei mentioned in his comment, this method seems to be just to delete bot sent message, not user sent message.
The only solution I can imaging is to provide a numeric password inline keyboard to user and ask him/her to enter password by pushing your numeric inline keyboard buttons. In this way nothing be logged in client, and you manage user input as callback data in server side.
Bad thing with this approach is that user became limited to numeric password.
Bot API 4.2 changelog (updated April 14, 2019):
The method deleteMessage can now be used to delete messages sent by a
user to the bot in private chats within 48 hours.
Since the method signature is not changed, any wrapper/framework (like python-telegram-bot) support this operation by now.
This seems to provide s a solution - https://github.com/yagop/node-telegram-bot-api/issues/328 .
Basically, there's a deleteMessage endpoint you can use - https://core.telegram.org/method/messages.deleteMessages, passing it the message ID. So when you get the message (with it's ID), just delete it.

Push notifications by username

I have been looking for ways to send notifications to specific users and what I found was that I need the device token to do that.
I have tried Firebase and Ionic Cloud Service to do some pushs and it worked fine, but I'm wondering if it's possible to register a service with a key -> value, for exemple, register with the username and the token. If so, how can I do it?
And what is the best service to do it?
Thank you in advance for the help.
P.S.: I'm not asking for code, just the theory.
From you question [for example, register with the username and the token. If so, how can I do it?] I understand following.
You mean to say, there is a mobile app, which user will sign up to use and you want to send the notification to registered user i.e. get send push notification by username.
To solve this, you can follow the steps mentioned below.
On app launch when you get FCM registration token, save it to some intermediate location such as local storages along with device-id, mobile details etc..
Create a backend API which can save username and registration token in DB.
When a user signs up or signs in, then fetch the registration token from local storages, post username, token to backend API to save it. You can make backend API bit intelligent to handle multiple devices of the single user, distinguishable by device-id, mobile details.
Then while sending API from the backend, you can fetch all registration ids of a single user and send the notification to that users using all tokens of that user in FCM API. Use registration ids as JSON array in "registration_id" field. FCM Document - link.

Show javascript alert() after sending async email into a different class

I have a VB ASP.NET aplication which at some point it has to send some emails (using System.Net.Mail).
I want to send them in background and once the sending finishes get some notification to know if the email was sent correctly or not (alert() the user). I tried to use SendAsync email, the problem is that in that way it freezes the UI, I also tried to encapsulate all the sending email method into a thread but after that the Httpcontext.current object is always null so I can't show the alert().
I have tried to search a solution around Stackoverflow but without any luck....

Is it Possible to have an ASP.NET Application in Microsoft Outlook

Users need to fill out an access request and once they are done and hit the submit, it emails the request to their supervisor.
Is it possible to email the entire form(with the user data and also to be filled fields by supervisor) in an email so that the supervisor can select accept and the change would be reflected in a SQL database from Outlook itself?
Emailing the form can be done. Writing an Outlook add-in can also be done. But you'll save yourself a lot of time if you just write an "approval" page in your web app and send a link to this page in the email to the supervisor. You can put any information you want in the email, of course.
ETA: But to actually suggest a solution: you could send an email that included a hyperlink, that included identifying information in the query string, and use that as a way of signalling to a web page or web service that the request should be approved. You'd have to work out something with security and authentication, of course, so that not just anybody could call that page and approve the request.

Resources