I have created a Facebook messenger bot that is working perfectly. I used php to create it.
Now, I want to add some new functionality. When the bot owner is online in Messenger and starts answering messages, the bot should stop responding to users.
How can i detect when the owner has started answering?
I did a test on this before.
You can try subscribing to "message_echo" webhook. This webhook is called when the page AND the bot sends a message to a user. So you'll need to differentiate which "message_echo" is from the page (a person) and which is from the bot. In the json that webhook sent, messages from the bot will contain an app_id key in the message object.
Your server will get a lot of hits by subscribing to this webhook.
A simple idea is to send the Bot a message from an administrator account. For example, if the admin sends 'STOP' then the Bot stops sending messages until an admin sends 'START'.
The incoming events to the Bot contains the sender id. The sender id would have to be correlated to a particular administrator id. The only way I have found to get that id for a particular user is to send a message and print out the id. The id is specific for the Bot and user combination. For example, my Bot will send a message to my personal account with this JS line:
sendTextMessage(1073962542672604,fistName + " " + lastName + " " + messageText); // send a message to Matthew directly
Sounds like you have a bot working but if you need more details, have a look at my Bot and source code.
Just for fun, I added this functionality to my Bot. To see details in the node.js implementation, search for the 'isStopped' variable in the app.js script.
Related
I've User ID's of multiple people. I want to send them a message using my BOT but, the problem is I don't have chat_id of an individual user because they haven't initiated a chat with the bot. Is there a way I can send a Direct message using User_ID (not with chat_id).
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/ links or username search to find your bot.
telegram.org
I have gone through many forums and API of telegram also.
But could not get the proper answer.
Well here is my main question.
I have list of users with their mobile numbers in my database and from all those, I want to send them messages on their telegram. So for that I will need their chat ID. How can I retrieve that by their MobileNumber? If I will have chat id, I am able to send message to them by using the following reference.
Telegram php example send message
I have visited the following link to get the chat id by manually from BOT by user itself. But I want automatic from script.
How to obtain Telegram chat_id for a specific user?
Thanks.
I'm not familiar with PHP. but there is a way to do this:
As you know you can send a contact in telegram bot using its phoneNumber and a firsName (Doesn't need to be the real first name of the contact who owns that number).
After sending the contact to a chatID(no matter what chatID you choose, can be your own personal chat ID), you can look for its UserID.
Now if the person exists in Telegram you will get a long number that
stands for his/her UserID or chatID but if not the long will be 0.
In C# I used this piece of code to see whether a phone number exists in telegram or not and it worked very well.
string s = "+44...."; //the phone number
var req2 = await bot.MakeRequestAsync(new SendContact(update.Message.Chat.Id, s, "Name"));
if(req2.Contact.UserId == 0)
{
Console.WriteLine("The contact does not exist in Telegram");
}else
{
Console.WriteLine("The contact exists in telegram with UserID:{0}",req2.Contact.UserId.ToString());
}
I believe this can be done in PHP too.
By Telegram bot you can send messages only to users that started chat with your bot. you can obtain their chat_id (not phone number) from received query.
So you can not send message to another people even if you have their phone numbers.
You can't use bots to find a user on Telegram using their phone number.
Basically, I am now making a basic social network app on iOS platform, using PHP as the backend. I am be able to make the login, register functions in my social network app, however, I am now struggling how to add friend in my app.
As far as I know, I have to make a table for making_friends, just following this tutorial: http://www.9lessons.info/2014/03/facebook-style-friend-request-system.html
However, what I wonder is, if one user send a friend request to another user, then the "status" in the "making_friends" table maybe "0", to indicate that the friend request is sent and waiting for the reply. But how to let the other user know, that a user is sending a friend request to him, and then the other user may accept the friend request and updating the "status" to "1", which means the other user accepts the friend request.
In a word, I am not sure how to communicate from one client to another client, using server as a bridge. Does anyone have any good suggestions?
You can use push notification to send a request to a client or hit to server periodically and check the status but this is not a good way to handle it
For ios push notification check this Apple Push Notification Services
You can INSERT both users as one record in making_friends table and make a status for it.
making_friends table
--------------------
User1
User2
Status
Once a user inserted in this table you can make a flag on status and let the user know the request
I've logged in and used the Facebook CHAT api all right. The problem is that I want to have a system where anyone can send me a message, without actually being on the friend list.
When the sender is in the friend list, I see the message. Is there a possibility that I can configure my account to receive messages from anyone, independing on if they are in the friend list or not?
Best Regards.
The Chat API and the Message API are not the same.
You may want to think of Chat as a subset of messages.
When a message is received and the user is a friend you receive a chat notification, if not, no response.
I have created an application which can post to users wall or even send emails to selected users, what I have not been able to come up with is the functionality to let an application send a message to users facebook inbox, I have googled it and found that applications are not allowed to send messages to users inbox however there's this product called rockmelt browser which does the same thing.
There's has to be some way which allows sending messages to users inbox.
Can somebody guide me on this?
It appears that you cannot send a message to a user's inbox. The closest thing may be this http://developers.facebook.com/docs/reference/rest/livemessage.send/. It allows you to send a live message to a particular user's browser.
Hope this helps.
If you are sending the message from your application user to one of their Facebook friends, you can use a Request, which will show up in the notification area. When the user clicks on the notification, they'll be taken to your App Canvas where you can show them the full message and any other app interactions you want.