Extending WeChat|Telegram
- Why WeChat & Telegram?
- Background & Statistics
- Telegram & Developers
- WeChat & Developers
- Conclusions & Considerations
Why WeChat & Telegram?



Popular mobile messengers



Similar functionalities: chat, call, share images/videos
Viber
Tango
Skype
Telegram
LINE
kik



Large user base, but no open API
1 billion registered users
600 million registered users
300 million active users
Has open API



700m users
100m users
600m users
350m users
275m users
Similar apps

Include contents within apps, in apps purchase


Develop & share bots
Backgrounds & Statistics
- Cloud-based instant messaging service
- supported by the Russian-born entrepreneur Pavel Durov
- Mobile text and voice messaging communication service
- in Chinese Wēixìn; literally: "micro message"
- Developed by Telegram Messenger LLP
- Released on August 2013
- Proprietary server license, GPL client license
- Requires phone number verification
- 100 million users around the world
- Developed by Tencent Holdings Limited
- Released on January 2011
- Proprietary license
- Can login using Facebook
- 100 million users outside China
Android
iOS
Web
Windows Mobile
Blackberry
Symbian
Supported Platforms
Telegram major advantages
- Has two-way opt-in - requires add/accept contacts before messaging
- Smaller app size
- Can send documents
- Has end-to-end encryption - avoid interception, only intended users can receive messages
- Message history synchronization
- Has temporary text & images option - self destruct message
- Best performance compared other messaging apps - fast and use least resource
WeChat major advantages
- Has two-way voice chat
- Can stay invisible
- Built-in QR code scanner
- Has video group chat
- Has language translation function
- A lot of social functions - find nearby users, 'drift bottle', chat with random strangers
- Has in-app payment function
- Online-offline (O2O) & Peer-to-peer (P2P) commerce core strategy
- i.e. Media partners can build in-app micro-sites & charge users subscription fees, user can send another user/group money, online stores
Telegram & Developers
Two options for developers:
- Bot API
- Telegram API
Bot API
- Third-party applications that run inside Telegram
- Users can interact with bots by sending them messages, commands and inline requests
- Developer control bots using HTTPS requests to Telegram bot API
What can we do with bots?
- Get customized notifications and news. A bot can act as a smart newspaper, sending you relevant content as soon as it's published.
- Integrate with other services. A bot can enrich Telegram chats with content from external services.
- Create custom tools. A bot may provide you with alerts, weather forecasts, translations, formatting or other services.
- Build single- and multiplayer games. A bot can play chess and checkers against you, act as host in quiz games, or even take up the dungeon master's dice for an RPG.
- Build social services. A bot could connect people looking for conversation partners based on common interests or proximity.
How to create bots?

- Talk to BotFather bot
- Follow steps to create bot
- Receive authorization token
- go to https://core.telegram.org/bots/api
- start coding your bot
- host your code


- Add bot into group or
- Send query to @botname
Bot Examples




Examples Bot Codes
<?php
define('BOT_TOKEN', '12345678:replace-me-with-real-token');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
function apiRequestWebhook($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
}
// more definitions
// ...
// more definitions
function processMessage($message) {
// process incoming message
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
if (isset($message['text'])) {
// incoming text message
$text = $message['text'];
if (strpos($text, "/start") === 0) {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array(
'keyboard' => array(array('Hello', 'Hi')),
'one_time_keyboard' => true,
'resize_keyboard' => true)));
} else if ($text === "Hello" || $text === "Hi") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you'));
} else if (strpos($text, "/stop") === 0) {
// stop now
} else {
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => 'Cool'));
}
} else {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'I understand only text messages'));
}
}
define('WEBHOOK_URL', 'https://my-site.example.com/secret-path-for-webhooks/');
if (php_sapi_name() == 'cli') {
// if run from console, set or delete webhook
apiRequest('setWebhook', array('url' => isset($argv[1]) && $argv[1] == 'delete' ? '' : WEBHOOK_URL));
exit;
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
// receive wrong update, must not happen
exit;
}
if (isset($update["message"])) {
processMessage($update["message"]);
}Available Bot Codes Example Languages
- PHP
- Phyton
- Java
- C#
- Ruby
- Go
- Lua
- Node.js
- Haskell
Telegram API
- Basically create your own Telegram
- Customize UI (buttons, colors, keyboards etc.)
- Enable or disable features
- Configure access or limitations
- Obtain our own api_id
- Fork from https://github.com/DrKLO/Telegram
- Code is in Java
Examples


- Cutegram - Focus on user friendliness & desktop platform
- Loopy - Real-time collaboration tool, real-time list, real-time memos etc.

WeChat & Developers
WeChat Extensions
Two options for developers:
- WeChat API
- WeChat Official Account
WeChat API
- Include WeChat media sharing library into our apps

WeChat API


Sharing via WeChat Message
Sharing via WeChat Message
WeChat API
- Register for App ID
- Download the WeChat SDK (libammsdk.jar & Sdesktop widget source code for Android) (libWeChatSDK.a, WXApi.h, WXApiObject.h for iOS)
- Add files into development environment


4. Start coding
WeChat API
WXMediaMessage is used to share rich media from our apps to WeChat
WXMediaMessage msg = new WXMediaMessage();
msg.title = "Some Title";
msg.description = "Some Description";WXMediaMessage *message = [WXMediaMessage message];
message.title = @"Some Title";
message.description = @"Amazing Sunset";
[message setThumbImage:[UIImage imageNamed:@"res1thumb.png"]];Android example
iOS example
WXMediaMessage has an attribute mediaObject. It is used to assign rich media types. http://dev.wechat.com/wechatapi/messages-moments
WeChat Official Accounts
- Provide a formal way for companies to interact with their customers thru WeChat
- Promote their brands to WeChat users through the WeChat channel
- Type of accounts:

WeChat Official Accounts
Subscription Accounts
- Often used much like a daily news feed, as they can push 1 new update a day to their followers
- Interesting articles from Subscription Accounts usually only end up being widely read once people post them on their moments

WeChat Official Accounts
Service Accounts
- Only allowed to send 4 updates per month to their followers
- Can do much more than subscriptions accounts
- Can take payments & use WeChat coupons



WeChat Official Accounts
Enterprise Accounts
- Similar to Service Accounts
- Not visible to a normal user
- Designed for organizations’ internal processes and secure communication
WeChat Official Accounts
Basic Platform Features
Available to all type of OAs

WeChat Official Accounts
Basic Developer Tools
Available to all type of OAs

WeChat Official Accounts
Advanced Developer Tools
Requires verified service or enterprise account

WeChat Official Accounts
Advanced Developer Tools
Requires verified service or enterprise account

Conclusions & Considerations
Pro
Fast & secure
Cons
Only a messaging app
Pro
Built-in payment & social functions
Cons
Bulky & privacy not guaranteed
Extending Wechat/Telegram
By hizumi
Extending Wechat/Telegram
- 1,621