摘要： 本文讲的是How to Interact with PHP Web Site Users using SMS, WhatsApp, Facebook or Telegram - PHP Classes， Author: Joseluis Laso Posted on: 2015-11-18 Package: PHP Telegram CLI Wrapper Nowadays many sites n
Author: Joseluis Laso
Posted on: 2015-11-18
Package: PHP Telegram CLI Wrapper
Nowadays many sites need to interact with Web users. The best way to do it is to use the instant messaging system that each user prefers.
Read this article to learn how to implement instant message based user interactions in your PHP Web site using SMS, WhatsApp, Facebook or Telegram.ByJoseluis Laso
< email contact >Introduction
We often want to have more ways to interact with the users of our Web site, blog or portal. We want to be able to notify these users about new contents or tell them that we are expecting some action from them.
The traditional way to implement that task has been done using email. Although email is totally fine, this is a slow method that does not provide real and immediate interaction.User Notifications
First I would like to take this opportunity to talk about how to properly implement an instant notification method that involves the user directly. Of course we have to respect always the local laws where our service will be available.
In any case we should respect always these three principles:
1) The user has accepted to receive our notifications
2) The user can reject our notifications in any moment.
3) User can change the frequency of notifications.
With these principles in mind, let's see which methods are available to do this task of sending immediate notifications to our users.What Means Can We Use For Interacting with Our Site Users?
These are the main methods that come to my mind to notify users:
1) Using your own site native mobile app push notifications
2) Send SMS messages to the user phone
3) Send social application messages: WhatsApp, Telegram, Facebook, Line, etc..
I believe that the first method provides a much closer interaction level with the user and often is the the one that gets the fastest reaction from his part.
Obviously, having your own site mobile app can attract more users. Although it is also true that they only can use it after having downloaded and installed the app on their smartphones.Good Purposes for Interacting with Our Site Users
Think about stuff like publication of new content, prompt the user for an action required in order to continue processing something, new interaction with the site or with other users. This is more obvious when we talk about intranets and company online applications.
Let's focus our attention in a real world example of mine.As some of you know I am the owner of tradukoj.com, a collaborative environment to help developers to translate their own developments, mainly made with PHP and Symfony.
Just imagine that you have a tradukoj account and you are translator of several projects. If the site had the possibility to notify you when there are new strings pending to translate, what do you prefer? Would you provide your email or you mobile phone number just to be notified? Let's depart from the assumption that yes, you provide your email or phone number.
Just imagine that you put your mobile phone number. The question is: What do you prefer to receive? An SMS saying that there are new strings pending to translate or a message in your social message app that allow us even respond with the translated string?
The rest of the article will give you some criteria to let you decide which messaging means are the best for your purposes and how can you use them in your own PHP projects. Keep in mind there is no single solution. You can create your own mobile app, as well you can send SMS messages in PHP with several solutions available in the PHP Classes site.Social Application Messaging
For now, let's focus in how to use social messaging apps in our own benefit. In this case we will start with the most common social chat applications: WhatsApp, Facebook, Telegram.WhatsApp
Without any doubt, Whatsapp is the most popular messaging app around the world. For sure you will reach the largest part of your users.
The main problem is that the only library that exists to access WhatsApp API is not authorized by WhatsApp and so it is not supported by the WhatsApp team. You can try it at your own risk.
In my case I have to say that I installed successfully this PHP library for testing purposes and I used it to send and receive messages from and to users, although I am a bit scared after reading some comments around the Web about its use. It is said that you can lose the possibility to use your mobile number to access WhatsApp, as you can be banned for WhatsApp for the rest of your life.
Following the installation steps on its repository, you can successfully send and receive messages from other users. My advice if you do not want to get banned, use a brand new number instead of your current number.
Also try to follow the steps to use optional libraries, because more of current users use the encryption support, otherwise you can not talk to them.
In my humble opinion, I think WhatsApp should recognize that developers want to use their app and provide methods to do that in an authorized way.
Here you can find the unofficial WhatsApp API that I am talking about.Facebook
Facebook is obviously the most popular social network. There is no more to say about this fabulous application. You can use for instance this PHP class to send notifications to your Facebook users .Telegram
Telegram is also a popular social chat application that I think it is a better option for developers to Interact with our users. It has an offical API and strong support directly by the Telegram staff team.
The only question is which one of the two available APIs we going to use?
We have the native or legacy API , that allows us to use telegram in the same way we use on the smartphone app or in desktop app. We can send and receive messages in our own phone number.
The other choice is to use the Bot API . It is much easier to use but for me it is not the right way to control notifications. Each user has to add our bot on his telegram app. So, we lose the control of which user is using our system or not. And there is no real and customized interaction.
The worst part is that the first option has only a cli app that runs on console.
Following the work of zyberspace I have created my own Telegram CLI wrapper class to easily use the methods that telegram-cli provides directly from PHP.Conclusion
In this article we learned about the different methods that we can use to send instant messages to our site users and how we can implement these methods in PHP.
In the following part of this article we will see how we can send automated messages to our users from a crontab script, how we can take simple orders from our users to do simple things, andhow to integrate other apps like webchat.
If you liked this article or have questions about the different instant messaging methods we can use in our sites, post a comment here.You need to be aregistered user orlogin to post a comment
|web server-centos6.5...||PHP如何利用P3P实现跨域_php技巧||[转]类与PHP （I）|
|...ed: PEAR/PECL (which includes the pecl executable) ...||...or maintaining a stateful session with a user or au...||Classes and PHPRod Kreisler The hardest concept I've t...|