New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sinatra-wechat

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinatra-wechat

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Sinatra Wechat extension

Build Status Gem Version Coverage Status

This extension is used to support Tencent Wechat rapid development.

Installation

$ gem install sinatra-wechat

Usage

Below code implement a simple wechat robot, reply text 你好 when message sent by end user contains number %r{\d+}.

use :validate_msg => false to disable wechat message validation, otherwise need to append signature to the URL. The default value of :validate_msg is true

# app.rb
require 'sinatra'
require 'sinatra/wechat'

wechat('/', :wechat_token => 'test-token', :validate_msg => false) {
  text(:content => %r{\d+}) {
  	content_type 'application/xml'
  	erb :hello, :locals => request[:wechat_values]
  }
}

__END__
@@ hello
<xml>
  <ToUserName><%= from_user_name %></ToUserName>
  <FromUserName><%= to_user_name %></FromUserName>
  <CreateTime><%= Time.now.to_i %></CreateTime>
  <MsgType>text</MsgType>
  <Content><![CDATA[你好]]></Content>
</xml>

start web server:

$ ruby app.rb

validate it via cURL:

$ curl -X POST --data '<xml>
<ToUserName>tousername</ToUserName>
<FromUserName>fromusername</FromUserName> 
<CreateTime>1348831860</CreateTime>
<MsgType>text</MsgType>
<Content>1345 match number</Content>
<MsgId>1234567890123456</MsgId>
</xml>' http://localhost:4567

The response is like:

<xml>
<ToUserName>fromusername</ToUserName>
<FromUserName>tousername</FromUserName>
<CreateTime>1405790652</CreateTime>
<MsgType>text</MsgType>
<Content><![CDATA[你好]]></Content>
</xml>

FAQs

Package last updated on 20 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc