Viber REST API, how to find Unique Viber user id? - api

Resource URL https://chatapi.viber.com/pa/send_message
General send message parameters
I am trying to send message to viber from Postman. I don't know how to find Unique Viber user id, that parameter is required.
I am getting this error:
{"status":999,"status_message":"Bad receiver ID","message_token":5126721184521938239}

Danny Dainton mentioned the docs on how you can get data including unique ID about your own account not about somebody else!
You'll receive callbacks containing user unique ID to your webhook if a user subscribes to your public account, and ONLY THEN you'll be able to send message to that user.
As per viber docs:
The send_message API allows accounts to send messages to Viber users who subscribe to the account. Sending a message to a user will be possible only after the user has subscribed to the Public Account by pressing the subscribe button or by sending a message, or by sending a message to a bot (see subscribed callback for additional information).
and VERY IMPORTANT
Before an account can send messages to a user, the user will need to
subscribe to the account. Subscribing can take place in one of two
ways:
User sends message to the account (both Public Accounts and bots)
when a user sends its first message to a account the user will be
automatically subscribed to the account. Sending the first message
will not trigger a subscribe callback, only a message callback (see
receive message from user section). Subscribed event is sent to the
Public Account (Public Accounts only)
user clicks a subscribe button
which triggers the subscribe callback as described below.

Simple, just call the Get Account Info API, whose resource URL is https://chatapi.viber.com/pa/get_account_info
You will find the a list of all subscribers in the response along with their user IDs. Please note that these user IDs are unique per user per public account.
Correction: It seems like the Get Account Info API does not return all subscribers, it just returned for me my user ID (the admin of the public account). Based on this, there is no way to get the user IDs of your subscribers other than from the callbacks for new subscribers, messages, ...etc.

Normally you should collect Viber IDs from all callbacks and store in DB for future use. But if you missed that step you can collect Viber IDs of online subscribed users by periodic call to get_online endpoint and then use get_user_details endpoint to get more info about unknown ones.

Related

Twitter API get webhooks for my account [PHP]

Do you know if it is possible to set up webhooks when there is activity on MY twitter account with API ?
For example :
notification when I receive a like on my tweet
notification when I receive a new subscriber on my account.
Etc ...
Thank you.
Yes. Once you have created a webhook, and subscribe to the webhook using your own account, you will receive the follow and reply events. Per the Account Activity API documentation, I've highlighted the two relevant bullet points:
You will receive all related activities below for each user subscription on your webhook registration:
Activity types Tweets (by user)
Tweet deletes (by user) #mentions (of
user)
Replies (to or from user)
Retweets (by user or of user)
Quote Tweets (by user or of user)
Retweets of Quoted Tweets (by user or of
user)
Likes (by user or of user)
Follows (by user or of user)
Unfollows (by user)
Blocks (by user)
Unblocks (by user)
Mutes (by user)
Unmutes (by user)
Direct Messages sent (by user)
Direct Messages received (by user)
Typing indicators (to user)
Read receipts (to user)
Subscription revokes (by user)
Note that you have to manually subscribe your own account to your own registered webhook using the API - this does not happen automatically. You also need to handle each received API event (the webhook will receive all types of event).

How to get authenticated by Telegram bot in Group chats?

Please kindly someone explain me how can the Telegram bot could understand who is sending the command in group chats and respond it with the the unique answer which is just for that user.
Surely in this case security issues should be considered and a user must not send command as another user.
I guess I can use username to send along with command.
Any suggestions...
The Message Object contains two objects apart from other objects:
Chat, message['chat'] which represents the Chat from which the message is coming. In your case the group.
User, message['from'] which represents the user that sent the message/command.
So it's easy to differentiate which user sent the message. And in case of Private chats, both the Chat object and the User Object are same.

Send message to th all of bots users (telegram api)

how to send Send message to the all of bots users?
There is no way to sned message to all ?
what is the method name ?
From Official API FAQ:
How can I message all of my bot's subscribers at once?
Unfortunately, at this moment we don't have methods for sending bulk messages, e.g. notifications. We may add something along these lines in the future. (...)
Obviously, if you store users chat_id, you can send individual message to all users (I use this method).
Navid wants to send message to all subscribers via bot.
If subscribers are more than 100 persons bot will very slow to sending all messages and may doesn't send messages to all.
Navid's question was how we can send message without this problem?
you can send with curl_multi_exec
Currently, a developer would need to implement a special broadcasting function that would send the message to each active user at the time adding a small delay to avoid hitting the rate limit of 30 messages per second (see https://core.telegram.org/bots/faq#how-can-i-message-all-of-my-bot-39s-subscribers-at-once). This would mean that a very popular bot with say 10K active users cannot give timely notification as the last user would get the message about 5 minutes after the first user.
Here is a feature request to ask to add a method in the Bot API to broadcast a message to all its active users at once. You can upvote this feature request. https://bugs.telegram.org/c/8463

YouTube API. Check for user was subscribed

What the best way to determine when authorized user was subscribed to YouTube channel by channel's id through YouTube Data API? I assuming it is possible somehow by "Subscriptions.list" API method. But how exactly?
If you know the channelId of the channel you want to check the user is subscribed to, you can perform an HTTP GET request on the subscriptions/list endpoint with the parameters part set to id and mine set to true:
HTTP GET https://www.googleapis.com/youtube/v3/subscriptions?part=id&mine=true&key={YOUR_API_KEY}
You could also pass in snippet for part to get information about each channel the user is subscribed to. With this approach, you would have to iterate through every channel that authenticated user is subscribed to, and check if your channel exists in that list.
You could also send an authenticated POST request to the subscriptions/insert endpoint with the channelId of the channel you want to subscribe to with the part param snippet, and if the user is already subscribed to that channel, the request will return a 400 error with the message subscriptionDuplicate.
HTTP POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}

How can I send message to specific chatID?

I have chatId and want send messages while execute some tasks from java code. I found this explain on telegram "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." But my task works good when I use https request directly from browser. My bot perfectly answer for requests but how I can do this without user request?
I can not truly understand your case!
Anyway, your bot can send a message to a chat ID Only if the user witch blongs to the specified chat ID added your bot (send start to a bot).
and if it happened then send your message with
/sendMessage