Bot replying to app_mention event in the wrong channel - php

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.

Related

How to send FCM Notification to a list of specific device tokens using the v1 API

I want to use the new FCM HTTP v1 API, which is documented here
FCM HTTP v1 API Documentation, to send a notification to multiple devices at once, but without using topics, or groups (let's say I want to send a notification to 10 random winners of some lottery). I know that in the previous version (Legacy FCM HTTP Protocol), this was possible by using the registration_ids parameter, but I don't see anything similar in the current API. Am I missing something? Is there a way to do this without using the legacy API?
There is currently no other way to send to multiple tokens besides using topics for FCM v1.
In your mentioned use case, if I'm using v1, I would probably go at something like, after selecting the winning tokens, you subscribe them to a topic like winningTokens<date_here> then send the message.
For other use cases, the best way to send to multiple devices via v1 API depends on your application. For example, the accepted answer would not be a good solution for a private chat application where another user can guess the topic name and evesdrop on the conversation by subscribing to the topic. In that scenario iterating over the device list and making multiple send calls to a single device would be better.

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.

PHP telegram API read group chat messages

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.

AWS SNS Endpoint subscription to a topic

Instead of creating an endpoint in an application and using that endpoint to create a subscription in a topic, Is it possible subscribe to a topic directly with the Registration Id. Also just want to know if it is possible to do it in PHP.
Please help me here.
It's not to possible subscribe an endpoint to a topic directly with the Registration Id (or token). You will first need to subscribe the device to an Application. You can then send direct pushes to the endpoints or subscribe them to your topics.
Note that "when you delete an endpoint that is also subscribed to a topic, you must also unsubscribe the endpoint from the topic", it's not unsubscribed automatically ~ http://docs.aws.amazon.com/sns/latest/api/API_DeleteEndpoint.html.
You can use AWS SDK for PHP to subscribe your endpoints to your topics, for more information, see http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sns.SnsClient.html#_subscribe
AWS does not provide a way to do that automatically, but you can easily handle it in your code.
Take a look at this StackOverflow thread for more information and sample code in Objective-C: "You can directly call the Subscribe API after you have created your endpoint. Unlike other kinds of subscription, no confirmation is necessary with SNS Mobile Push".

Php button push notification android

I'm trying to implement push notification but I'm a little bit lost.
I just want to have a button in php and when I click it, a notification appear in all devices telling the users something like: "A new image is available in the web".
I read the GCM documentation but I'm not sure how to start.
I see that in some examples the users have to send their emails in order to register their "sender id"? it is necessary? I want the user don't have to register anywhere.
Can someone help me to start or give me a quick tutorial?
Thank's for all.
You will need to use curl to call the GCM, you can find examples like this all over SO, for example : how to send a notification to millions of android devices in php using GCM (first one that came up in a search)
And of course you will need the registration id's otherwise GCM doesznt know which device to send the notification to.
The solution is not so simple. You should at least use some package dedicated to this specific service. Also, you should read something about what push notifications are.
There are many services out there you can use to interface yourself with this specific kind of service.
Take a look to this service to get a first idea about the entire mechanism. Remember that you have to subscribe to a push service provider for every platform you want to use. For example the Apple Push Notification Service, or Cloud Messaging by Google.
Hope it's a good start for you.

Categories