PHP telegram API read group chat messages - php

Is it possible to create a PHP script which allows me to receive telegram messages out of group chat. I am following a group channel on Telegram with my personal account. The messages I receive needs to be processed by PHP. I know it is possible to create a bot, but can a bot do this? Is it able to join a channel/group and read all new messages?
I cannot find an answer to do so.
For example I'm in telegram.me/thisgroup. All the messages needs to be received by PHP and in the end stored in a database. The database part is not hard, but receiving it is.
Does somebody know how to?
Thanks!

It's possible by using bot API.
By default bots can't recive all messages. but you can change this setting.
here is the document about this: https://core.telegram.org/bots#privacy-mode
Create bot.
Change Privacy Mode of the Bot.
Add bot to group
Setup webhook to recive messages or use getUpdates method.
Store messages to your database.

Related

Bot replying to app_mention event in the wrong channel

I'm trying to work with the slack Event Subscription app_mention, but I'm having some issues.
My backend is PHP, and I'm using this class.
Basically, what's happening is, if I have my bot user in multiple channels and someone mentions the bot, it will only reply in a single channel.
For example;
I have the bot user in 2 channels
bot-testing
development
If I # mention the bot in the development channel, it will send it's reply in the bot-testing channel.
My code used to send the message:
$client->to('#' . $event['channel'])->send("Hi. I'm currently under development.");
and my $event variable looks like this:
{"type":"app_mention","text":"<#UFT4EG0Q7> test","user":"UAKTRFH41","ts":"1548783398.055200","channel":"GAMED4PK5","event_ts":"1548783398.055200"}
but decoded obviously.
Why is my bot not replying in the correct channel?
So based on my reading of the PHP client you're using, that's designed for use with Incoming Webhooks.
Incoming Webhooks have a 1:1 relationship with a conversation/channel, so you can't define the destination for your message in the payload you send to the API.
If you want to do that, you could try using one of the other PHP SDKs built by the community.

Trigger Slack Bot by Direct Message

I'm realy new to this Bot stuff.
I want to create a simple PHP-Skript that is sending an answere every time the Bot is contacted by a user via Direct Message.
I read the Api-Docs but the only thing I found was the /-Command.
Currently I have a Cronjob thats checking the RTM-Api for new messages.
I think there must be a better way then running a Cron-Job every few seconds to check if there is a new message for the Bot.
I found the "EmojiBot" that is exactly responding in the way I want.
Using the RTM API to build a bot will work, but there is indeed an easier way: Use the new Event API from Slack.
The Event API allows you to subscribe to range of events. When the event happens, Slack will automatically call your php script. So you don't need to run a CRON loop. This also works with bot users and direct messages to bot users.
Check out the Event API documentation for details.
You can use Botonomous Framework which supports Events API. You should subscribe to the events, then update the framework configurations which is explained here. Finally you have got a nice event object and based on certain criteria you can send a message back to a Slack channel.

Firebase chat notifications via PHP to SMS + EMAIL

We have firebase chat application (check any chat example or tutorial) that will have same copy as our.
We would like to sent email notification or sms message, if user hasn't seen the chat message yet.
We can connect to firebase database with php and check all the messages, if they are seen or not. but It's not really proper way of doing it.
Does anyone have idea how we can implement that, so we can track of all the messages and if they haven't seen it, then sent the email / sms notification based on user preference?
I just want to know how we can do that with firebase. if it was just php and mysql. it was really easy to do this.
Not sure if this can be done efficiently in Firebase. You will have to setup a cron job to fetch the messages which are not seen and trigger SMS/Email fallback.
I would recommend using Applozic (https://www.applozic.com) for Chat related stuff and Firebase for storing user meta data and other data.
Applozic provides a single click configuration to enable Webhook/SMS/Email fallback, along with that you will get all the whatsapp like chat features along with full UI with no need to write any additional code.

How to send a message to a third-party Telegram bot and retrieve the response using PHP?

I've searched both SO and Google and couldn't find what I need. I'm trying to see if it is possible to send a message to a Telegram bot (which I'm not it's owner/writer) and receive the response. The bot that I'm trying to communicate with through my PHP script will get a text message and in return sends back a proper file regarding the initial request. I want my web server be able to send that request and save the returning file in a specific folder on my server.
Is this possible at all?
What I've been seeing all over is sending messages to users as a Telegram bot. In here I want to do it the other way, sending a message to a bot as a user.
Many thanks

Telegram problems with updates

I'm trying to create a simple bot for Telegram, I have settled the webhook correctly.
My problem is that I'm not able to get updates using file_get_contents("php://input"). I obtain the JSON object only if I use file_get_contents($mywebsite."/getUpdates"); and in that way I'm able to obtain the info of the chat.
Anyway I can send messages only if I reload my web page and not directly from the Telegram app.
How can I fix this problem?

Categories