Send an initial message when people first invite the Telegram bot - telegram-bot

I am using Python and have previously built Telegram chatbot before.
However, now I want to create a chatbot such that when someone invites it, it will send an initial message that says something like "type /start for instructions".
This is to make sure that they know what to do when they first invite the bot. Can this be possibly done?
I am trying to use bot.send_message(chat_id=chat_id, text="type /start for instructions") but the problem is I don't know how I could obtain the chat_id.

Unfortunately, you cannot do it :(
Here has another way you might interested: /setdescription in #BotFather.
It will be shown in the What can this bot do? section as the picture below.

After digging this issue - here's what I've found:
The reason:
Intuitively it seems logical to allow a feature that sends a message to a user (as a reaction to the user's action for starting the chat). BUT, because telegram APIs are truly vast there is a fair chance for abuse in this format (a message with button that drives the user for action without the user truly understand the consequences). From here my question changed from "how to implement this mechanism?" to "Which alternative do I have?"
There is an alternative!
My initial goal was to make the "what can I do here" factor as clear and effortless to the user as possible. Technically speaking - all methods that can be invoked without the chat_id can be invoked as part of your bot setup process and will affect all users. One option is to create a list of commands to your bot. This list will appear when the user use the / operator and it's a common practice among chat users. For my intention - I needed something even simpler than that and I think that the setChatMenuButton is very suitable. This method allows you to create a web app and allows the user to simply click it instead of typing text. When clicking the button it triggers a dialog that clarifies to the user what's going on and from there - it's basically your imagination that will define how the end-user will experience your process. I managed to execute this call using a wrapper that I've build (which handles the base url as well as secret key) using this code:
await api.get('setChatMenuButton', {
menu_button: JSON.stringify({
type: 'web_app',
text: 'Name of your app here',
web_app: { url: 'https://your-domain.com/ppp/path/goes/here' }
}),
})
More about Telegram Web Apps
And a little screenshot from my experience:

Related

How can I search for messages (embeds) with a particular 'author' through DiscordSocketClient?

I'm in the process of building a new Discord bot (of course), and I've been working on the Twitter integration using Tweetinvi. I've got most of the Twitter streaming bits working normally (at least, as far as I can tell in my simplified testing), but I wanted to have the bot modify/delete posts in Discord if the Tweet is subsequently deleted. Tweetinvi has a TweetDeleted event that I can use to detect this as a part of my stream, but I'm having difficulty figuring out how to find the post in Discord.
What I'd like to do is "simply":
Search for posts (embeds) from the author (defined by the original Tweet)
Find the post with a matching .Url value in the embed
Replace that post with a message like "THIS TWEET WAS DELETED".
The problem I'm running into, however, is I can't seem to find a way to do "step 1" - search for and return any posts from the specified author. The only option I've found so far is the GetMessagesAsync method, but that doesn't seem to have a way to filter the results. Plus, with the "soft limit" of 100 messages, I worry that I could still not find the message I'm looking to delete.
I post the embeds using the DiscordSocketClient object in my class like this:
Me.A1FDiscordClient.GetGuild(Server.ID).GetTextChannel(PostingChannel).SendMessageAsync(MessageText.Trim, False, TweetBuilder.Build)
I had started working on something similar for the deletion/modification, but I think I'm simply spinning my wheels at this point:
Dim Messages = Me.A1FDiscordClient.GetGuild(Server.ID).GetTextChannel(PostingChannel).GetMessagesAsync(100)
I'm probably being dense and/or completely overlooking something, but I'm not even sure what to do with this once I have it. I was looking at using the .Select(Of TResult), but I think I've just gotten myself too twisted. I don't necessarily need a whole solution, but I could really use someone giving me a nudge in the right direction.
Discord does not provide an endpoints for Bots to search/filter on specific criteria. The only way to retrieve messages is to use the GetMessagesAsync() method
The limit for GetMessagesAsync() is technically Int32.MaxValue. The 100 that you see is simply the default. This is because Discord will return in chunks; 100 messages at a time. For example if you set the limit to 1000, you will get 10 chunks of 100.
Possible issues with retrieving a large number of messages? The main issue would be the length of time taken to retrieve the messages, which could block the gateway unless offload the process to its own task.
A possible solution would be to implement your own system for linking and storing twitter posts to discord posts. Could be as simple as a dictionary of Twitter post id and discord post id which would allow you to easily find the message id related to a given twitter post.

Client does not want invalid logins to redirect

I would like to ask this question to developers who have a good sense of design. I see that whenever a website uses a popup box for their login page, they will always post and then redirect to the next page whether it be content or a dedicated login page for an invalid login error.
I have a client who has been asking to cut out as much page refreshing as possible, including the login function. They would like to see the login error appear on the login popup box without a page refresh.
I have not noticed a web based businesses do this, so I'm wondering if there's a valid reason to avoid this. I personally think that a page refreshing allows users to recognize their input has been registered and the next page appearing will be a solid response to their action either good or bad.
Having no refresh and expecting the user to notice that some error text has appeared seems like a bad idea?
Notes
The question is most likely more appropriate for https://ux.stackexchange.com .
You can find a lot of stuff by searching "ajax logins" in a search engine
There already is this question that might indeed be a duplicate of this one. Since I was not sure and I had already wrote most of this answer before finding that I post it nonetheless.
The title ought to be changed to a question (maybe something like "Is it a bad idea to use ajax to return login errors?").
Actual Answer
In my opinion ajax logins could indeed make less clear whether there really has been a successful interaction with the server or not.
Some ideas to improve it might be:
to include the time of the login request in the error message
to explicitly assure in the error message that the credentials have been received and checked
to be sure that this error does indeed only occur after the credentials have been determined to be not valid (and not because of problems with scripts or the network, for example).
A good way to ensure this might be to have the server always send the full text of the error, rather than a code that selects a message stored in the page source (and to be careful its caching).
This becomes relevant only after the user has been using the site for some time, of course (and has incurred in the error and verified that it was indeed due to a mistake on his part).
to use some animated feedback to highlight the dispatch and the reception of the reply to the user. As with the text you should ensure that the animations do not give (too) incorrect indications.
Basically these suggestions would be applicable to any ajax form entry, but they are more important for logins because:
in this context it's a lot easier to make typing mistakes (in the typing of the password)
and mistakes have a drastic, immediate annoying outcome: the inability to authenticate and the necessity to input again the entire password
And so uncertainties on whether the input has really been received and processed are a lot more bothering.
All in all anyhow it's pretty complex to do this well, with both an appealing appearance and a reassuring feedback.
The ones ajax logins that I've incurred into did not do a good job (I think I have indeed experienced false login errors with them).
You can find several ajax login frameworks/plugins by searching for "ajax logins". I have not looked into any of them.

Twitter -- Tracking single user's tweet using API

I am having a hard time solving this dilemma, and I have a feeling that it's been done a million times, I just cannot find any documentation on it. What I am trying to do:
I have a button on my site that pops open a Twitter window and allows a user to tweet a reformatted message that I have defined.
<a onclick="window.open('https://twitter.com/intent/tweet?original_referer=<?php echo $_page_url?>&source=tweetbutton&text=<?php echo $tweet_message ?>&url=<?php echo $_page_url?>', '', 'height=500,width=650,modal=yes,alwaysRaised=yes resizable=1 scrollbars=1');">
<img src="/share/twitter_share.png" alt="share now" width="94" height="23" />
</a>
What I am needing is a way of tracking if this person has successfully tweeted this message and the user id or username returned for storage in a database. The reason for this is that I want them entered in this database ONCE. We are having a giveaway based on a single share/tweet, and they only get one entry per username/id.
I have tried multiple ways to retrieve the ID or username of current logged in user, mostly using the https://api.twitter.com/ to return JSON to no avail. I have also read the following:
https://dev.twitter.com/docs/platform-objects/users
https://dev.twitter.com/docs/platform-objects/tweets
And am now stuck. All I need is a return for user id that I can attach to the above window. Does anyone know how I can accomplish this? Thanks!
It cannot be done using this approach, at least not with true certainity. All you can do is track if 1) the window was successfully open using onclick and 2) if the window was closed (you can assume that perhaps the user completed the tweet).
You will NOT able to get ANY information from you open window via Javascript because the window is NOT in your domain (meaning, it is not on your server but on Twitter's).
What you want to do is implement this functionality in code as opposed to a javascript popup window. I have seen a number of commerical products that do exactly what you are describing.
The documentation (links) you provided refer to the REST API for Twitter (which usually works on the server) that is VERY different from Twitter's Web Intents which is client site javascript plugin, which has no similar API.

May we use Yii flash messages on this scenario?

I haven't seen this scenario covered here:
Yii Framework: How to work with Flash Messages.
So, after user registration, I wish to redirect the user to a thank you page where he/she could read more about what he/she should do, and what would happen next. It's a nice amount of information, so adding that message to an already existing page is not an option, because it would get to noisy. Making temporary displaying msg isn't an option neither, because it's a fair amount of text to be read.
On cases like this:
Should we still use flash messages and use a conditional so that what normally exists on the page stays hidden while display a success flash message ?
OR
Should we simply redirect to a given thank you view (by creating the respective thankyou action?)
Is there a better option?
You could use a flash message. But these are really for things like "Your account is now created".
If you want to include a good amount of information, I think it best to have a separate thankyou action/view that people are redirected to after the sign up process is complete.

FQL Testing Tool Vanished?

This is my first post here, so I should probably start by saying thankyou for the myriad of issues you have helped me to resolve.
http://developers.facebook.com/docs/reference/rest/fql.query/
The fql.query page had a utility that allowed you to build FQL statements and test their results using one of your Applications access tokens. Is it just me or has it vanished?
You now use the Graph API Explorer tool for testing everything.
In the large dialog box, you type fql?q= followed by your query. e.g: fql?q=SELECT username FROM user WHERE uid = me()
There are other buttons that let you use a custom access token or one of your page's tokens methods.
agrees with cpilko, use the Graph API Explorer.
You can bookmark this link instead, It auto switches the tab to FQL https://developers.facebook.com/tools/explorer?fql